# Defining a precise x-axis max in plot()

Hello Gentlepeople,

I am plotting an integer array using: matplotlib.pyplot.plot().
For my purposes it is imperative that the x-axis be explicitly defined.
I have tried to achieve this by using: matplotlib.pyplot.axis(v).
Where v is a list of integer values corresponding to the desired axes limits [xmin, xmax, ymin, ymax].
However, the x-axis that is displayed does not obey my explicit xmax declaration; the value is rounded up.

Here is the relevant portion of my code:

fig = pyplot.figure(figsize=(16,8))
ax1 = fig.add_axes([0.05, 0.15, 0.9, 0.8])
v = [0, len(myintvector), 0, max(myintvector, key=int)]
ax1.axis(v)
ax1.plot(myintvector, 'r--')

The reason that I need the x-axis to match the length of my integer vector is because I am also drawing a colorbar immediately below the plot, the values of which describe the same integer vector. Therefore I need the colorbar coordinates to match the x-axis coordinates of my plot.

I hope that I have described my issue coherently. Please be kind (N00b alert).
Any help is greatly appreciated!

Sincerely,
Lionel 'Lee' Brooks 3rd

Hello Gentlepeople,

I am plotting an integer array using: matplotlib.pyplot.plot().
For my purposes it is imperative that the x-axis be explicitly defined.
I have tried to achieve this by using: matplotlib.pyplot.axis(v).
Where v is a list of integer values corresponding to the desired axes
limits [xmin, xmax, ymin, ymax].
However, the x-axis that is displayed does not obey my explicit xmax
declaration; the value is rounded up.

Here is the relevant portion of my code:

It is always better to provide a minimal but complete self-contained example illustrating the problem.

fig = pyplot.figure(figsize=(16,8))
ax1 = fig.add_axes([0.05, 0.15, 0.9, 0.8])
v = [0, len(myintvector), 0, max(myintvector, key=int)]
ax1.axis(v)
ax1.plot(myintvector, 'r--')

I am not seeing the problem when I try what I think is a minimal example; what version of mpl are you using? And have you tried calling axis after the call to plot? This might have been necessary in some earlier versions; I don't recall.

ax1 = gca()
ax1.axis([0,9.9,0,9.9])
ax1.plot([1,2])
draw()

in which no rounding occurs.)

Eric

ยทยทยท

On 01/24/2011 02:49 PM, Lionel (Lee) Brooks 3rd wrote:

The reason that I need the x-axis to match the length of my integer
vector is because I am also drawing a colorbar immediately below the
plot, the values of which describe the same integer vector. Therefore I
need the colorbar coordinates to match the x-axis coordinates of my plot.

I hope that I have described my issue coherently. Please be kind (N00b
Any help is greatly appreciated!

Sincerely,
Lionel 'Lee' Brooks 3rd