简体   繁体   中英

Matplotlib: plot string on y axis

I am plotting two lists on the Y and X axis:

Y-list

1
1
1
1
2
2
3
3

X-list

2015-07-08 00:00:00
2018-02-05 00:00:00
2018-02-05 00:00:00
2018-03-08 00:00:00
2018-03-08 00:00:00
2019-07-30 00:00:00
2019-07-30 00:00:00
2019-11-18 15:00:00

In the final graph I would like to display a time-hisotry. Do you know how I can replace the single Y-values with names/strings (Generator1, Generator2, Generator3). See picture.

Thank you!

在此处输入图片说明

You can use yticks for this https://matplotlib.org/3.1.1/api/_as_gen/matplotlib.pyplot.yticks.html

for example

yticks(np.arange(5), ('Generator1', 'Generator2', 'Generator3', '4', '5'))

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