我在x和y轴上有值,并试图在子图上生成简单的折线图。这是显示问题的简单而基本的示例。
import matplotlib.pyplot as plt
x1 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58,
59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72]
y1 = [24.892730712890625, 25.268890380859375, 26.677642822265625, 28.294586181640625, 29.477203369140625,
30.61334228515625, 31.656219482421875, 32.371551513671875, 31.412261962890625, 31.973724365234375, 31.563812255859375,
30.72821044921875, 29.249237060546875, 26.759185791015625, 26.081024169921875, 25.27996826171875, 24.69805908203125,
24.92388916015625, 24.76177978515625, 24.385498046875, 24.093231201171875, 23.92156982421875, 23.788543701171875,
23.67657470703125, 23.581085205078125, 23.92095947265625, 25.90557861328125, 27.767333984375, 29.196136474609375,
30.25726318359375, 31.262786865234375, 32.2996826171875, 32.92620849609375, 33.32098388671875, 33.228057861328125,
30.495269775390625, 29.17010498046875, 28.04144287109375, 27.326202392578125, 24.904205322265625, 23.775054931640625,
24.1328125, 24.195343017578125, 23.751312255859375, 23.55316162109375, 23.459228515625, 23.304534912109375,
23.233062744140625, 23.093170166015625, 23.15887451171875, 25.13739013671875, 27.397430419921875, 28.923431396484375,
29.945037841796875, 30.976715087890625, 31.93109130859375, 32.665435791015625, 32.701324462890625, 31.212799072265625,
30.201507568359375, 29.591888427734375, 28.002410888671875, 27.72802734375, 27.371002197265625, 26.072509765625,
25.39373779296875, 25.196044921875, 25.2684326171875, 24.815582275390625, 24.27130126953125, 23.758575439453125,
23.49615478515625, 23.3907470703125]
plt.subplot(513)
plt.plot(x1, y1, 'b-')
plt.grid(True)
plt.show()
一切正常。但是输出图在xaxis上有一些空白。这是显示问题的图像:-
感谢您为解决该问题提供的任何帮助。
最佳答案
=您可以使用xlim来覆盖“ AutoLocator”在后台引入的这种行为:
plt.subplot(513, xlim=(0,72))
# or
plt.subplot(513, xlim=(x1[0], x1[-1]))
您还可以像本示例(和其他示例)中所示调整Locator:
http://matplotlib.org/examples/pylab_examples/major_minor_demo2.html