axes

How do I ensure that my matplotlib axes are of a custom class?

天涯浪子 提交于 2019-12-03 16:26:01
I have a custom figure class and would like to ensure that all of the axes associated with it, whether created with subplots() or twinx() , etc. have custom behaviors. Right now I accomplish this by binding new methods to each axis after it has been created, e.g. by using import types def my_ax_method(ax, test): print('{0} is doing something new as a {1}.'.format(ax, test)) class MyFigure(matplotlib.figure.Figure): def __init__(self, **kwargs): super(MyFigure, self).__init__(**kwargs) axes_a = None axes_b = None axes_c = None def setup_axes(self, ax): self.axes_a = ax self.axes_b = self.axes_a

Plotting two axes in gnuplot

久未见 提交于 2019-12-03 11:36:26
问题 Is it possible to plot two curves, with two corresponding axes in gnuplot, each of which has a different scale? For example, y=x**2 and y=x**4 in the same graph (they vary enough to be "uncomfortable" when plotted with the same scale). 回答1: You can have the axes handled automatically without you having to scale them yourself and keep auto-scaling: set terminal jpeg set output 'graph.jpg' set xrange [-10:10] set ytics 10 nomirror tc lt 1 set ylabel '2*x' tc lt 1 set y2tics 20 nomirror tc lt 2

Matplotlib: get and set axes position

老子叫甜甜 提交于 2019-12-03 11:19:12
问题 In matlab, it's straightforward to get and set the position of an existing axes on the figure: pos = get(gca(), 'position') set(gca(), 'position', pos) How do I do this in Matplotlib? I need this for two related reasons: These are the specific problems I'm trying to solve: I have a column of subplots where some have colorbars and some don't, and they aren't the same width i.e. the X axises don't align. The colorbar steals space from the axes. This also happens in matlab, and there I'd use the

How to show x and y axes in a MATLAB graph?

有些话、适合烂在心里 提交于 2019-12-03 10:38:48
I am drawing a graph using the plot() function, but by default it doesn't show the axes. How do we enable showing the axes at x=0 and y=0 on the graph? Actually my graph is something like: And I want a horizontal line corresponding to y=0 . How do I get that? By default, plot does show axes, unless you've modified some settings. Try the following hold on; % make sure no new plot window is created on every plot command axes(); % produce plot window with axes plot(% whatever your plot command is); plot([0 10], [0 0], 'k-'); % plot the horizontal line dysan This should work in Matlab: set(gca,

Removing frame while keeping axes in pyplot subplots

有些话、适合烂在心里 提交于 2019-12-03 09:36:40
问题 I am creating a figure with 3 subplots, and was wondering if there is any way of removing the frame around them, while keeping the axes in place? 回答1: If you want to remove the axis spines, but not the other information (ticks, labels, etc.), you can do that like so: fig, ax = plt.subplots(7,1, sharex=True) t = np.arange(0, 1, 0.01) for i, a in enumerate(ax): a.plot(t, np.sin((i + 1) * 2 * np.pi * t)) a.spines["top"].set_visible(False) a.spines["right"].set_visible(False) a.spines["bottom"]

matplotlib: overlay plots with different scales?

匿名 (未验证) 提交于 2019-12-03 08:57:35
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: So far I have the following code: colors = ('k','r','b') ax = [] for i in range(3): ax.append(plt.axes()) plt.plot(datamatrix[:,0],datamatrix[:,i],colors[i]+'o') ax[i].set(autoscale_on=True) With the autoscale_on=True option for each axis, I thought each plot should have its own y-axis limits, but it appears they all share the same value (even if they share different axes). How do I set them to scale to show the range of each datamatrix[:,i] (just an explicit call to .set_ylim() ?) And also, how can I create an offset y-axis for the third

pyplot axes labels for subplots

匿名 (未验证) 提交于 2019-12-03 08:48:34
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have the following plot: import matplotlib.pyplot as plt fig2 = plt.figure() ax3 = fig2.add_subplot(2,1,1) ax4 = fig2.add_subplot(2,1,2) ax4.loglog(x1, y1) ax3.loglog(x2, y2) ax3.set_ylabel('hello') I want to be able to create axes labels and titles not just for each of the two subplots, but also common labels that span both subplots. For example, since both plots have identical axes, I only need one set of x and y- axes labels. I do want different titles for each subplot though. I tried a few things but none of them worked right 回答1: You

matplotlib Axes.plot() vs pyplot.plot()

匿名 (未验证) 提交于 2019-12-03 08:48:34
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: What is the difference between the Axes.plot() and pyplot.plot() methods? Does one use another as a subroutine? It seems that my options for plotting are line = plt.plot(data) or ax = plt.axes() line = ax.plot(data) or even fig = plt.figure() ax = fig.add_axes([0,0,1,1]) line = ax.plot(data) Are there situations where it is preferable to use one over the other? 回答1: For drawing a single plot, the best practice is probably fig = plt.figure() plt.plot(data) fig.show() Now, lets take a look in to 3 examples from the queston and explain what

Matplotlib stops animating after first frame

匿名 (未验证) 提交于 2019-12-03 08:36:05
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I'm trying to animate two subplots, each with multiple lines. I am using Matplotlib , and I am using the FuncAnimation , which is used by many of the animation examples . Using animation: If I try to animate it, I only get the result of the first frame: Without using animation: If I manually call my update_lines function, it works fine. Code: Below is the full code (uncommenting the 3 indicated lines in main() works, but I would like to see it update in real-time, hence trying to use the animation). import matplotlib . pyplot as

Matplotlib: Adding an axes using the same arguments as a previous axes

匿名 (未验证) 提交于 2019-12-03 08:36:05
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I want to plot data, in two different subplots. After plotting, I want to go back to the first subplot and plot an additional dataset in it. However, when I do so I get this warning: MatplotlibDeprecationWarning: Adding an axes using the same arguments as a previous axes currently reuses the earlier instance. In a future version, a new instance will always be created and returned. Meanwhile, this warning can be suppressed, and the future behavior ensured, by passing a unique label to each axes instance. warnings.warn(message, mplDeprecation,