Closed yywe closed 6 years ago
When you plot you get back the full dictionary of all matplotlib plots. Use the plot for the image and add a colorbar to the figure yourself.
fig.colorbar(cm, ax=ax)
Where cm
is the image you want the colorbar for, ax
is the axis you want the colorbar to be added and fig
is the figure which contains cm.
The returned plot is fig = m.plot(). The problem is from the fig object, I did not find the image, and also what do I pass for the second parameter ax?
fig.figure.images is empty
Solved: This wasn't obvious : )
Using help from this stackoverflow answer:
Immediately after you call m.plot()
, call:
ax = plt.gca() #get current axes
mappable = ax.collections[0] #this is specific for what the surface call returns
plt.colorbar(mappable)
More notes/comments on GPy's code: Relevant code is line 214 in GPy/plotting/gpy_plot/gp_plots.py
- an issue is this returns a dictionary, with gpmean
set to a list of plots, which is what we really need for setting the colorbar properly. However, this method's plots list is fed into the add_to_canvas
method by plot
(line 351). The add_to_canvas
method doesn't use the plots argument, so its content is, I guess, not accessible later. Hence why you're having trouble I guess finding it.
Addendum: This doesn't work if you've set the plot_data
parameter to False
.
When I fit a Gaussian Process Regression model by calling 'GPy.models.GPRegression'. then I want to plot the model so I call 'm.plot(property='3d'). I know the highlight area usually have a larger value, but how can I show the related color bar for the colours. any help? thanks so much.