0

Using the pandas API to matplotlib, I'm making a plot - with four subplots - of quantities in a dataframe. Now it's working well, but I'm having problem getting control of the colorbar that is automatically added to each axis. (There's a colorbar added because I'm plotting hexbin plots).

See the example here: https://pandas.pydata.org/pandas-docs/stable/visualization.html#hexagonal-bin-plot .

My goal is to set the label of the colorbar, but I'm unsure how to even go about this using the pandas API. My code for the first subplot is below:

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() returns 8 objects, so the colorbar axes are there... I just need to know how to find (get a handle on) them. Thanks

0

1 Answer 1

0

After much searching, I found that a similar question was asked here: Getting Colorbar instance of scatter plot in pandas/matplotlib

Because of the way the pandas matplotlib API works when a plot (scatter or hexbin) requires a colorbar, this has to be done manually by returning the axes in the figure and then manually working out which correspond to the colorbars. This can be done using

axes_list = fig.get_axes()
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.