Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting the display range suplot of errorbars in matplotlib

I'm trying to plot my data using matplot lib. I have 3 separetes sets of data I want to plot in 3 subplots (I'm using this is my guidence):

plt.figure()

fig, axs = plt.subplots(nrows=3, ncols = 1, sharex=False)
ax1 = axs[0]
ax1.errorbar(X,Y,Err,fmt='o')
ax1.set_xscale('log')
ax1.set_yscale('log')
ax1.set_title('epsilon=1.5, kappa = 2')
plt.show()

However I get the x range from 1 (or 0, I'm not sure) to 100 and I want to reduce it. I tried this, by adding using:

ax1.xlim(0.5,13.5)

But I get an error:

AttributeError: 'AxesSubplot' object has no attribute 'xlim'

How can I change the range then?

like image 773
Yotam Avatar asked Nov 22 '11 09:11

Yotam


People also ask

What does PLT subplot 1 2 1 mean?

The subplot() Function The layout is organized in rows and columns, which are represented by the first and second argument. The third argument represents the index of the current plot. plt.subplot(1, 2, 1) #the figure has 1 row, 2 columns, and this plot is the first plot.

Which parameter is used to set error bars on drawn vertical bars in a bar plot?

errorevery: This parameter is also an optional parameter. They contain integer values which is used to draws error bars on a subset of the data.

Which of the following parameter is used to set the Colour of error bar in bar plot?

ecolor: This parameter is an optional parameter. And it is the color of the errorbar lines with default value NONE. elinewidth: This parameter is also an optional parameter.


2 Answers

You might want to use Axes.axis(*v, **kwargs):

ax1.axis(xmin=0.5,xmax=13.5)

From the documentation:

Set/Get the axis properties

If len(*v)==0, you can pass in xmin, xmax, ymin, ymax as kwargs selectively to alter just those limits without changing the others.

like image 190
Andrey Sobolev Avatar answered Oct 02 '22 22:10

Andrey Sobolev


The corresponding method of axis object is set_xlim(xmin,xmax).

like image 24
tillsten Avatar answered Oct 02 '22 21:10

tillsten