简体   繁体   中英

How to scale x-axis in matplotlib with unequal gaps

I have to following table:

在此处输入链接描述

and I create the following graph with this code:

code :

plt.plot(new[201], label='201')
plt.genend()
plt.show()

graph:

在此处输入链接描述

how can I scale the x-axis NOT to be with equal gaps?

for example, if I use the same data in excel I get this graph:

在此处输入链接描述

so how can I make the graph in python to be like in excel?

You seem to have your data as strings. Most likely the x-axis is occupied by string values. You have not provided the data, so I have no idea what new[201] looks like. However, I guess all you need is to cast it to float with something like:

new[201].astype(np.float)

Of course, this is for numpy array. In case your data have a different format, check the specific way to cast it from string to float.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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