pandas 绘图 - 多个颜色条
pandas plot - multiple colorbars
如何使用 pandas 散点图正确绘制 2 个颜色条?现在第一个颜色条被复制:
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);
可以直接使用matplotlib函数:
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)
产生
如何使用 pandas 散点图正确绘制 2 个颜色条?现在第一个颜色条被复制:
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);
可以直接使用matplotlib函数:
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)
产生