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.60开发者_Python百科000000000031, 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?
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])
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).
精彩评论