简体   繁体   中英

Python Matplotlib lineplot with multiple x-axis data causing common y-axis issue

New to Python and this is my first work with Matplotlib. I'm trying to plot multiple data sets on to a single lineplot but I'm having issues with getting the y-axis to display properly.

The x-axis is time in seconds. The y-axis are numerical values. All the data sets are brought in as a dictionary key:value pair where the value is a list.

Displaying one plot seems to work OK (Plot 1) but any time I add more than one data set - it looks like the y-axis is displaying a separate range for each of the plots (Plot 2)?

I have noticed that people seem to use numpy arrays rather than lists but I'm working with the format the data is in currently.

There was a similar question asked here Multiple plots on common x axis in Matplotlib with common y-axis labeling but that person was seeing different issues to me.

kline_data_dict = {'time': ['14:27:00', '14:27:00', '14:27:00', '14:27:00', '14:27:02', '14:27:02', '14:27:02', '14:27:02', '14:27:04', '14:27:04'], 'open': ['20854.76000000', '20854.76000000', '20854.76000000', '20854.76000000', '20861.38000000', '20861.38000000', '20861.38000000', '20861.38000000', '20861.38000000', '20861.38000000'], 'close': ['20862.47000000', '20862.47000000', '20862.47000000', '20862.47000000', '20861.80000000', '20861.80000000', '20861.80000000', '20861.80000000', '20864.65000000', '20864.65000000'], 'high': ['20879.99000000', '20879.99000000', '20879.99000000', '20879.99000000', '20864.16000000', '20864.16000000', '20864.16000000', '20864.16000000', '20869.73000000', '20869.73000000'], 'low': ['20846.30000000', '20846.30000000', '20846.30000000', '20846.30000000', '20860.27000000', '20860.27000000', '20860.27000000', '20860.27000000', '20860.27000000', '20860.27000000']}

plt.plot(kline_data_dict['time'], kline_data_dict['low'])
plt.plot(kline_data_dict['time'], kline_data_dict['high'])
plt.show()

Plot 1 Plot 2

Possible answer from this post: Matplotlib y axis values are not ordered [duplicate]

The list elements for the y-axis elements were input as strings. Converting them to float() seems to have solved this.

Plot 3

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