【问题标题】:Finding colorbar axis in pandas hexbin plot using pandas matplotlib API [duplicate]使用pandas matplotlib API在pandas hexbin图中查找颜色条轴[重复]
【发布时间】:2018-05-29 19:21:09
【问题描述】:

使用 pandas API 到 matplotlib,我正在绘制一个数据帧中的数量图 - 有四个子图。现在它运行良好,但我无法控制自动添加到每个轴的颜色条。 (添加了一个颜色条,因为我正在绘制 hexbin 图)。

请参阅此处的示例:https://pandas.pydata.org/pandas-docs/stable/visualization.html#hexagonal-bin-plot

我的目标是设置颜色条的标签,但我不确定如何使用 pandas API 来解决这个问题。我的第一个子图的代码如下:

fig, axes = plt.subplots(nrows=2, ncols=2, figsize=(8, 8))
p1 = go65.plot.hexbin(x='si10_hx', y='tcc_hx', C='dsst_amp_bias', reduce_C_function=np.mean,\
             gridsize=25, vmin=-1.5, vmax=1.5, cmap = plt.cm.PiYG,\
             xlim=(0, 35), ylim=(0, 1),\
             ax=axes[0,0])

fig.get_axes() 返回 8 个对象,所以颜色条轴就在那里……我只需要知道如何找到(掌握)它们。谢谢

【问题讨论】:

    标签: python pandas matplotlib plot colorbar


    【解决方案1】:

    经过大量搜索,我发现这里提出了类似的问题:Getting Colorbar instance of scatter plot in pandas/matplotlib

    由于当绘图(散点图或 hexbin)需要颜色条时 pandas matplotlib API 的工作方式,这必须通过返回图中的轴手动完成,然后手动计算出与颜色条相对应的轴。这可以使用

    axes_list = fig.get_axes()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-04-11
      • 2019-06-11
      • 1970-01-01
      • 2013-12-24
      • 2012-08-09
      • 2016-10-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多