hvplot icon indicating copy to clipboard operation
hvplot copied to clipboard

Area chart legend is in reverse order of chart sections.

Open LinuxIsCool opened this issue 4 years ago • 4 comments

It would be nice if the order of the legend matched the order of the stacked sections. I tried to find an easy way to reverse the legend, but couldn't find one. Thanks!

image

LinuxIsCool avatar Mar 14 '21 23:03 LinuxIsCool

Here is a working example of the above. I would like the legend to match the order of the columns, rather than being strictly alphabetical. Any hints would be appreciated. Thanks all.

import numpy as np
import pandas as pd
import hvplot.pandas

data = pd.DataFrame(np.exp(np.random.randn(100,3)/10),columns=['C', 'B', 'A']).cumprod()
chart = data.hvplot.area()
chart

image

LinuxIsCool avatar Apr 01 '21 01:04 LinuxIsCool

I've tried all of the following:

import numpy as np
import pandas as pd
import hvplot.pandas

data = pd.DataFrame(np.exp(np.random.randn(100,3)/10),columns=['C', 'B', 'A']).cumprod()
chart = data.hvplot.area(clabel=['C','B','A'])
chart.redim.values(Variable=['C','B','A'])
chart.redim.values(Baseline=['C','B','A'])
chart.redim.values(value=['C','B','A'])
chart

LinuxIsCool avatar Apr 01 '21 01:04 LinuxIsCool

Anyone have any idea on how to address this?

LinuxIsCool avatar Aug 12 '23 07:08 LinuxIsCool

As a workaround, you can use this:

def hook(plot, element):
    legend = plot.handles["plot"].legend
    legend.items = legend.items[::-1]
    
chart.opts(hooks=[hook])

image

hoxbro avatar Aug 14 '23 08:08 hoxbro