views:

34

answers:

2

alt text

I drew this graph using matplotlib using the following code.

import matplotlib
import matplotlib.pyplot as plt

x = [450.0, 450.0, 438.0, 450.0, 420.0, 432.0, 416.0, 406.0, 432.0, 400.0]
y = [328.90000000000003, 327.60000000000031, 305.90000000000146, 285.2000000000013, 276.0, 264.0, 244.0, 236.0, 233.5, 236.0]
z = [2,4,6,8,10,12,14,16,18,20]

plt.plot(z,x,'-',lw=3)
plt.plot(z,y,'--',lw=3)
plt.show()

As you can see the graph of x touches the axis boundary and does not look good. How can I change this?

A: 

I tried your code and the graph did not overlap. Anyway, try to add small margins to the plot:

plt.margins(0,0.02)

Also you may try to add argument clip_on=True to plot function call (but it should be set to True by default).

hluk
I get the following error when I add this line. Traceback (most recent call last): File "d:\code\sample.py", in <module> plt.margins(0,0.02)AttributeError: 'module' object has no attribute 'margins'
Bruce
maybe try: plt.plot.margins(0,0.02) ???
bigjim
+1  A: 

Use axis:

plt.plot(z,x,'-',lw=3)
plt.plot(z,y,'--',lw=3)
plt.axis([2,20,100,500])
plt.show()

Or, use ylim:

plt.ylim([100,500])
Steve