简体   繁体   中英

Python Matplotlib: Drawing 2d line without sorting xdata

How can I tell matplotlib to not sort xdata given as input when drawing a matplotlib.lines.Line2D ?

I want to create custom xticks which I create as strings, for example:

import matplotlib.pyplot as plt
x = ['1','2','10']
y = [ 1 , 2 ,  3 ]
fig,ax = plt.subplots()
ax.plot(x,y)
plt.show(block=False)

and I get x values drawn in the order ['1','10','2'] , ie they get lexicographically sorted. How can I get them drawn in the original order?

Thank you for your help!

You need to upgrade your matplotlib to version 2.2.0 or higher. (Current version is 2.2.2)

This will solve your problem automatically because it respects the order of the input.

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