Skip to content
Advertisement

Ploting multiple curves (x, y1, y2, x, y3, y4) in the same plot

I’m trying to plot a graph with four different values on the “y” axis. So, I have 6 arrays, 2 of which have elements that represent the time values ​​of the “x” axis and the other 4 represent the corresponding elements (in the same position) in relation to the “y” axis.

Example:

JavaScript

The coordinates of the “LT” graph are:

JavaScript

And with these coordinates, I can generate a graph with two “y” axes, which contains the points (-110,-113,-3,-5) and an “x” axis with the points ('18:14:17.566', '18:14:17.570').

Similarly, it is possible to do the same “GNR” arrays. So, how can I have all the Cartesian points on both the “LT” and “GNR” arrays on the same graph??? I mean, how to plot so that I have the following coordinates on the same graph:

JavaScript

plot

Advertisement

Answer

It sounds like your problem has two parts: formatting the data in a way that visualisation libraries would understand and actually visualising it using a dual axis.

Your example screenshot includes some interactive controls so I suggest you use bokeh which gives you zoom and pan for “free” rather than matplotlib. Besides, I find that bokeh‘s way of adding dual axis is more straight-forward. If matplotlib is a must, here’s another answer that should point you in the right direction.

For the first part, you can merge the data you have into a single dataframe, like so:

JavaScript

To visualise the data as a dual axis line chart, we just need to specify the extra y-axis and position it in the layout:

JavaScript

enter image description here

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement