1

I'm using two related packages that generate plots I want to overlay for comparison. I call a method called plot_spectro from each package which plots to plt. Then I must do plt.legend() and plt.show() to see them. What happens is two plots with the same data ranges appear, but I would like to overlay (superimpose) them.

import matplotlib.pyplot as plt

s.plot_spectro(xaxis=x, yaxis=y)

plt.xlim(-6,2)
plt.ylim(-2.5,2.5)

o1.plot_spectro(xaxis=x, yaxis=y,  color='b')

plt.xlim(-6,2)
plt.ylim(-2.5,2.5)

plt.legend()

plt.show()

1 Answer 1

2

Create an axis instance and pass it to both the plots as shown below

import matplotlib.pyplot as plt

fig, ax = plt.subplots()

s.plot_spectro(xaxis=x, yaxis=y, ax=ax) # <--- pass ax=ax here
o1.plot_spectro(xaxis=x, yaxis=y,  color='b', ax=ax) # <--- pass ax=ax here

plt.xlim(-6,2)
plt.ylim(-2.5,2.5)

plt.legend()
plt.show()
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.