简体   繁体   English

Matplotlib 在大范围内绘制非常小的 X 轴间隔?

[英]Matplotlib Plotting Very Small X-axis Interval in a big Range?

My X axis data is like this:我的 X 轴数据是这样的:

 X =[0.0, 0.9, 0.99, 0.999, 0.9999, 0.99999, 0.999999, 0.9999999, 0.99999999, 0.999999999, 0.9999999999, 0.99999999999, 0.999999999999, 0.9999999999999, 0.99999999999999, 1.000000000000001, 1.00000000000001, 1.0000000000001, 1.000000000001, 1.00000000001, 1.0000000001, 1.000000001, 1.00000001, 1.0000001, 1.000001, 1.00001, 1.0001, 1.001, 1.01, 1.1]

My Y axis data is like this:我的Y轴数据是这样的:

Y = [1.0, 3.16227766016838, 9.999999999999995, 31.622776601683782, 100.00000000000551, 316.22776601755754, 999.9999999856221, 3162.277661000621, 9999.999974876204, 31622.777048860404, 99999.99586298171, 316227.7529344374, 1000011.0610435781, 3161786.1272856337, 10003998.786452563, -30011996.35935769, -10003998.786452563, -3163542.1874750517, -999955.5526723525, -316227.7529344374, -99999.99586298171, -31622.77529344374, -10000.000030387355, -3162.2776592452046, -1000.0000000411333, -316.2277660158021, -100.00000000000551, -31.622776601685537, -9.999999999999995, -3.162277660168378]

I want to plot this data and I should be getting a graph with curves but all I get is this:我想要 plot 这个数据,我应该得到一个曲线图,但我得到的只是:

plt.plot(X,Y)
plt.show()

#output:

错误的绘图 - 使用 X 和 Y 数据时的图像

But when I use this code:但是当我使用这段代码时:

​plt.plot(range(30),Y)
plt.show()

#Output:

正确的情节但错误的 X 轴刻度

How do I get Second Plot but using the X data of the List as mentioned above?如何获得 Second Plot 但使用上述列表的 X 数据?

So this is the answer:所以这是答案:

import matplotlib
from matplotlib.pyplot import figure
figure(num=None, figsize=(18, 16), dpi=80, facecolor='w', edgecolor='k')
plt.plot(range(29), Y, 'o-')
ax = plt.gca()
fmtr = matplotlib.ticker.IndexFormatter(X)
ax.xaxis.set_major_formatter(fmtr)

#Outputs: 

它是如何需要的

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM