0

For some reason this question is tough for me to explain, but here goes. I have a set of data say (x,y1,y2) that I would like to plot. I need it to be one plot, not two plot one being (x,y1) and the other being (x,y2). Instead I want it so i can plot it at once and then have the left axis be for (y1) and the right axis be for (y2).

Currently I am stuck at plotting two separate plots and having to scale the axis to match each other, yet it still isn't working too well. Below I put my code that plots, the set of data is mesaBV=x...mesaMv=y1...mesaAge=y2

Is anyone familiar with answering this question? Thanks!!

Edit:

host = host_subplot(111, axes_class=AA.Axes)

par1 = host.twinx()

par1.set_yscale('log')

host.grid(True)    

host.set_xlabel("B-V")
host.set_ylabel("Mv")
par1.set_ylabel("Age")


p1, = host.plot(mesaBV, mesaMv, label="Mv",marker="o")
p2, = par1.plot(mesaBV, mesaAge, label="Age",marker="o")

host.set_yticks(np.linspace(host.get_ybound()[0], host.get_ybound()[1], 10))
par1.set_yticks(np.linspace(par1.get_ybound()[0], par1.get_ybound()[1], 10))

host.axis["left"].label.set_color(p1.get_color())
par1.axis["right"].label.set_color(p2.get_color())

plt.draw()
plt.show()
1
  • Please consider showing your code and your current plot. This will probably make it easier to understand your issue. Commented Aug 22, 2015 at 15:35

1 Answer 1

1

By having two y values for the same point, you are creating a vertical line. Unless you can scale the graph perfectly, it won't work, and even if you scale it perfectly, there would be no point (no pun intended) because y1 would be essentially in exactly the same spot as y2. If you truly need it like that, than just plot (x1,y1) and figure out a different scale for the right y-axis without having it affect the original points. This way you can easily emulate (x1,y1,y2).

EDIT: Now that I can see your code, I recommend using the twinx() function to create the second axis.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.