0

I am plotting some data in Python3 with matplotlib:

import matplotlib.pyplot as plt
d = list(range(0,10))
y = [ x*x for x in d]
plt.plot(d, y, c="r")
plt.ylabel("some unity")
plt.show()

where y and d are not the real data but were provided just to give a minimum working example.

What I would like to do is to put another scale and label on the right y-axis keeping the same graph.

So basically on the plot I have just one graph with one set of values in x and two set of values (two scales) in the y-axis one in the left and one in the right.

Is that possible?

NOTE: To make the question more clear, suppose I have the x, y1 and y2 lists of values where y2 is a transformation of y1. Instead of doing plot(x, y1) and plot(x, y2) which would result in 2 different curves, I want to have one curve (for example from plot(x,y1) using y1 as the left y-axis scale and y2 as the right y-axis scale, (each one having its own unity-measurement/label).

roschach
  • 8,390
  • 14
  • 74
  • 124
  • https://matplotlib.org/examples/api/two_scales.html – ImportanceOfBeingErnest Jun 13 '18 at 08:41
  • In the example you posted it seems to be using a default scale. It is not clear there how to change it the second scale (for example passing another list). – roschach Jun 13 '18 at 09:59
  • Sorry, I don't understand the problem. Both scales are automatically adjusted to the respective axes' content. Maybe you want to explain exactly what you are trying to achieve? – ImportanceOfBeingErnest Jun 13 '18 at 10:04
  • Suppose I have the `x`, `y1` and `y2` lists of values where `y2` is a transformation of `y1`. Instead of doing `plot(x, y1)` and `plot(x, y2)` which would result in 2 different curves, I want to have one curve (for example from `plot(x,y1)` using `y1` as the left y-axis scale and `y2` as the right y-axis scale. That what I was asking in the question before it was put on hold. – roschach Jun 13 '18 at 10:06
  • For that you would of course need the transformation. I will replace the duplicate link. – ImportanceOfBeingErnest Jun 13 '18 at 10:14

0 Answers0