Arviz: Color scheme not displayed in plot_energy.

Created on 15 Apr 2019  Â·  7Comments  Â·  Source: arviz-devs/arviz

The color scheme is not displayed in the legend for a default energy plot.
arviz-plot_energy-1

This behavior is not observed when we set kind='hist'.
arviz-plot_energy-2

All 7 comments

Good catch! I checked the code a little, and this is a problem of plot_kde. The label is set in ax.plot, therefore, when alpha=0 (or linewidth=0) in plot_kwargs the legend is empty. Here is another example:

>>> az.plot_kde(np.random.normal(size=1000), label="Gaussian", plot_kwargs={"alpha":0}, fill_kwargs={"alpha":.7}) 
# equivalent to
# az.plot_kde(np.random.normal(size=1000), label="Gaussian", plot_kwargs={"linewidth":0}, fill_kwargs={"alpha":.7})

Outputs:

plot_kde_wrong_legend

This can be solved creating the legend from handles. The only thong that will be a little tricky will be passing the arguments in plot_kwargs and fill_kwargs to the matplotlib Patch. I have plenty of experience with this kind of legends, I can try to solve it or help anyone who volunteers. It can also be useful to avoid the ghost plots in plot_energy when bfmi=True.

In this case, I'll start working on the issue and you can help me in the process.

Great! Feel free to ask anything via gitter. I will also send you some reference that may be useful. I have one starting comment though, which is interesting for everyone too. The docs say _use fill_kwargs={‘alpha’: 0} to disable fill_. And the same approach is used in plot_energy to disable the line plot. However, I think it may be a better idea to use linewidth=0 to disable line plots, which will also make it easier when generating the custom legend handles.

Amazing. I'll start work on this soon.

Do we really need the patch here? Could we just pop the label kw out from plot_kwargs and add it to fill_kwargs iff lw=0? Then maybe remove its alpha? Or atleast make sure it is not close to 0?

This is also an option, however the results when both line and fill are present could be weird. I am not sure if this would actually be less work to the patch in plot_kde. However, this approach will probably make solving the problems in plot_energy easier.

Issue's been resolved. I'll close it now.

Was this page helpful?
0 / 5 - 0 ratings