1

I need two plots on the same figure. One of them is described by a Dataframe and the other by numpy arrays. Is there a way to plot them on the same figure without converting any of them ?

I know how to make multiple plots if all are numpy arrays or if all are Dataframes, but I don't know what to do when they have mixed types. For example, the following does not work:

ax=plt.plot(xv,yv)
df.plot.scatter(x='Column1',y='Column2',ax=ax)
1
  • Can you share your data? What is xv, 'yv' and df? It makes life much easier Commented Aug 8, 2018 at 9:45

1 Answer 1

1

If you want two plots on the same figure:

fig, (ax1,ax2) = plt.subplots(2)
ax1.plot(xv,yv)
df.plot.scatter(x='Column1',y='Column2',ax=ax2)
Sign up to request clarification or add additional context in comments.

4 Comments

Sorry, I did not express myself well. I want them on the same plot, not on two separate subplots.
I tried using ax1 for both plots, it works but I end up with an empty and useless subplot.
Actually the same with plt.subplots(1) gets the job done. Thanks !
Okay, I misunderstood the result you were trying to get. You asked for two plots on the same figure, which in matplotlib language means two axes usually. In your case, it sounds like you want two plots on one axis.

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.