1

I am trying to plot different columns (longitude & latitude ) from different dataframes in one plot. But they are being plotted in different figures separately.

Here is the code I am using

fig,ax=plt.subplots()

cells_final.plot.scatter(x='lon',y='lat')
data_rupture.plot.scatter(x='Longitude',y='Latitude',color='red')
plt.show()

How can I plot this in one single figure?

2

3 Answers 3

1

Use the axes instance (ax) created by

fig, ax = plt.subplots()

And pass it as the ax parameter of pandas.DataFrame.plot,

fig,ax=plt.subplots()

cells_final.plot.scatter(x='lon',y='lat', ax=ax)
data_rupture.plot.scatter(x='Longitude',y='Latitude',color='red', ax=ax)
plt.show()

Or if you'd rather have the plots on different subplots in the same figure you can create multiple axes

fig, (ax1, ax2) = plt.subplots(1, 2)

cells_final.plot.scatter(x='lon',y='lat', ax=ax1)
data_rupture.plot.scatter(x='Longitude',y='Latitude',color='red', ax=ax2)
plt.show()
Sign up to request clarification or add additional context in comments.

Comments

0

You need specify the axis:

fig,ax=plt.subplots(1,2, figsize=(12, 8))

cells_final.plot.scatter(x='lon',y='lat', ax=ax=[0])
data_rupture.plot.scatter(x='Longitude',y='Latitude',color='red', ax=ax[1])
plt.show()

1 Comment

Actually I want both scatter plot with different colour from different data frames in one Plot rather than two different subplots
0

Output

Thanks @William Miller.......!

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.