简体   繁体   中英

pandas plot - multiple colorbars

How can I properly plot 2 colorbars with pandas scatter plots? Right now the first colorbar is duplicated:

https://gist.github.com/denfromufa/45c446690a69265d39dd

import numpy as np
import pandas as pd
df=pd.DataFrame(np.random.random([100,5]),columns='A B C D E'.split())
df.head()


%matplotlib inline
ax1=df.plot(kind='scatter',x='A',y='B',c='C',s=df.D*50,cmap='summer',linewidth=0,sharex=False);
df.plot(ax=ax1,kind='scatter',x='A',y='C',c='D',s=df.B*50,cmap='winter',linewidth=0,sharex=False);

You can use the matplotlib functions directly:

import numpy as np
import matplotlib.pyplot as plt
import pandas as pd   

df = pd.DataFrame(np.random.random([100,5]),columns='A B C D E'.split())

sc1 = plt.scatter(x=df['A'], y=df['B'], c=df['C'], s=50*df['D'], cmap='summer')
plt.colorbar(sc1)
sc2 = plt.scatter(x=df['A'], y=df['C'], c=df['D'], s=50*df['B'], cmap='winter')
plt.colorbar(sc2)

which produces

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM