0

Given a tidy Pandas column with 4 or more columns, I want an otherwise very straightforward plot: two of the columns should be the x-y axes of a single figure, and one of the columns should index an Overlay of N Curve objects based on the x-y columns, and N Spread objects, using the final column as error. So if N=4 there should be 4 curves and four spreads. The curves and spreads with same index should be the same color, and the legend should attest to this.

Using table.to(hv.Curve,'col1','col2') I can get a Holomap for the curves, and with some effort I can do the same for the spread. If I then call .overlay() I get a nice figure for the curves including a legend, but when I do the same for the spread the legend vanishes. If I overlay the two, the legend likewise vanishes and the color cycle stops working, making all curves and spreads the same color. If I create a Holomap of curve*spread objects, then the colors match but the legend is still gone.

This seems like a very standard plot, but I can find very little in the Holoviews docs about pairing different Elements or controlling the legend.

Bonnevie
  • 187
  • 9

1 Answers1

2

This is a bit difficult to answer without any concrete code, for example I can't reproduce some of the issues you are describing. However the first issue is simply that show_legend is not enabled by default for the Spread elemen. In the case of plotting a Curve and Spread using .to and .overlay, here is what I can confirm works:

%%opts Spread [show_legend=True width=600] Overlay [legend_position='right']
df = pd.DataFrame({
    'index': np.arange(100), 'y': np.random.randn(100).cumsum(),
    'err': np.random.rand(100)+0.1, 'z': np.repeat(np.arange(10), 10)
})
ds = hv.Dataset(df)
ds.to(hv.Curve, 'index', 'y', 'z').overlay() * ds.to(hv.Spread, 'index', ['y', 'err']).overlay()

enter image description here

If I create a Holomap of curve*spread objects, then the colors match but the legend is still gone.

This is indeed a current limitation since we recommended against nesting objects in this way in the past, however I have just opened this PR which will allow this approach as well.

philippjfr
  • 3,997
  • 14
  • 15
  • Separately I've opened an issue to make sure we add a section about legends, see https://github.com/ioam/holoviews/issues/2756. – philippjfr Jun 01 '18 at 13:03
  • This looks great! Only missing piece seems to be that the legend isn't labelled with the appropriate key dimension, which happens when it's e.g. just an overlay of curves. – Bonnevie Jun 02 '18 at 14:20
  • Agreed, this is a longstanding issue, if you're so inclined maybe bump the corresponding issue in bokeh: https://github.com/bokeh/bokeh/issues/6769 – philippjfr Jun 02 '18 at 14:24
  • Is there any way to override the default legend title? Or to add text to the pre-generated legend? Using the label property isn't really an option when using Table and the .to method. – Bonnevie Jun 02 '18 at 16:31