Reputation: 145
I'm using a for cycle to scatter more than one dataframe on a same pd.plot.scatterplot, but everytime the cycle return it print a colorbar. How can I have just one colorbar at the end of the cycle?
This is my code
if colormap is None: colormap='jet'
f,ax = plt.subplots()
for i, data in enumerate(wells):
data.plot.scatter(x,y, c=z, colormap=colormap, ax=ax)
ax.set_xlabel(x); ax.set_xlim(xlim)
ax.set_ylabel(y); ax.set_ylim(ylim)
ax.legend()
ax.grid()
ax.set_title(title)
Upvotes: 0
Views: 65
Reputation: 789
This can be achieved by using figure and adding the axes to the same subplot:
import pandas as pd
import numpy as np
# created two dataframes with random values
df1 = pd.DataFrame(np.random.rand(25, 2), columns=['a', 'b'])
df2 = pd.DataFrame(np.random.rand(25, 2), columns=['a', 'b'])
And then:
fig = plt.figure()
for i, data in enumerate([df1, df2]):
ax = fig.add_subplot(111)
ax = data.plot.scatter(x='a', y='b', ax=ax,
c='#00FF00' if i == 0 else '#FF0000')
plt.show()
You can add the labels and other elements as required.
Upvotes: 2