-1

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

robobozo
  • 113
  • 1
  • 5
  • Please clarify "the y-axis is displaying a separate range for each of the plots". Your data series have no overlap, so why would they not be separate in the plot? – mcsoini Jan 16 '23 at 18:55
  • @mcsoini I think I've found the issue causing this but there is overlap. In 'Plot 2' the bottom of the y-axis starts at 20846 and ends at 20869 but in the middle it is 20879 - so it's not in ascending order and both of the plots include common data point values. I'll update this post with what I think the problem is. Thanks. – robobozo Jan 16 '23 at 19:20

1 Answers1

0

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

robobozo
  • 113
  • 1
  • 5