带有轴对象的Python散点图颜色栏
我试图从一个表中生成一个简单的散点图,我想根据表中的一列对图中的点进行颜色编码。 到目前为止,我通过使用带有轴对象的Python散点图颜色栏,python,matplotlib,plot,Python,Matplotlib,Plot,我试图从一个表中生成一个简单的散点图,我想根据表中的一列对图中的点进行颜色编码。 到目前为止,我通过使用 fig = plt.figure(figsize=(14,10)) ax = fig.add_subplot(111) import matplotlib.pyplot as plt ax.scatter(sub_ZH_match[:,9], sub_ZH_match[:,10], c=sub_ZH_match[:,2], s=60, marker=mod_marker, edgecolo
fig = plt.figure(figsize=(14,10))
ax = fig.add_subplot(111)
import matplotlib.pyplot as plt
ax.scatter(sub_ZH_match[:,9], sub_ZH_match[:,10], c=sub_ZH_match[:,2], s=60, marker=mod_marker, edgecolors='black', cmap=cm.jet_r, label='matches')
显然,在哪里
sub_ZH_match[:,9] -> x values
sub_ZH_match[:,10] -> y values
sub_ZH_match[:,2] -> values for the color coding.
但我不知道如何在绘图的一侧显示颜色条
当使用此语法时,它会起作用
plt.scatter(sub_ZH_match[:,9], sub_ZH_match[:,10], c=sub_ZH_match[:,2], s=60, marker=mod_marker, edgecolors='black', cmap=cm.jet_r, label='matches')
clb = plt.colorbar()
clb.ax.tick_params(labelsize=18)
clb.set_label(r'$\nu$', fontsize=20)
但我想了解在坚持axes对象的语法时如何做到这一点。
谢谢 你试过这个吗
import matplotlib.pyplot as plt
fig = plt.figure(figsize=(14,10))
ax = fig.add_subplot(111)
scatter = ax.scatter(sub_ZH_match[:,9], sub_ZH_match[:,10], c=sub_ZH_match[:,2], s=60, marker=mod_marker, edgecolors='black', cmap=cm.jet_r, label='matches')
colorbar = fig.colorbar(scatter, ax=ax)