【发布时间】:2021-08-06 17:31:12
【问题描述】:
我有两个DataFrame 用于两个不同的数据集,其中包含RA、Dec 和Vel 列。我需要将它们绘制到相同的散点图并显示一个 colorbar 而不是两个。使用纯matplotlibhere 也有类似的问题,但我需要使用pandas 的散点图函数来完成。到目前为止,这是我的实验:
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
data1 = pd.DataFrame({'RA':np.random.randint(-100,100,5),
'Dec':np.random.randint(-100,100,5),'Vel':np.random.randint(-20,10,5)})
data2 = pd.DataFrame({'RA':np.random.randint(-100,100,5),
'Dec':np.random.randint(-100,100,5),'Vel':np.random.randint(-10,20,5)})
fig, ax = plt.subplots(figsize=(12, 10))
data1.plot.scatter(x='RA',y='Dec',c='Vel',cmap='rainbow',
marker='^',ax=ax,label='Methanol',vmin=-20, vmax=20)
data2.plot.scatter(x='RA',y='Dec',c='Vel',cmap='rainbow',
marker='o',ax=ax,label='Water',vmin=-20, vmax=20)
ax.set_xlabel('$\Delta$RA (arcsec.)')
ax.set_ylabel('$\Delta$Dec. (arcsec.)')
ax.set_title('Maser Spot')
ax.invert_xaxis()
ax.legend(loc=2)
使用此代码,我设法将两个DataFrame 绘制成一个散点图。但它显示了两个颜色条,如您在此处看到的:
Test Case.
感谢任何帮助。
【问题讨论】:
标签: python pandas matplotlib