2

I'm experimenting with Plotly as a pandas plot backend. I successfuly configured it following these instructions, but I'm having trouble to configure my chart element colors.

Here is what I want to do. It works with matplotlib as a backend:

df.plot(kind='area', 
        color=['orange', 'lightslategray'],
        backend='matplotlib' )

correct chart

But when I try using ploty, it fails with a strange error:

df.plot(kind='area', 
        color=['orange', 'lightslategray'], 
        backend='plotly' )

The error:

ValueError: All arguments should have the same length. The length of argument `color` is 2, whereas the length of  previously-processed arguments ['Dia', 'Alfa', 'Beta'] is 12

The plot works if I don't try to set any color:

df.plot(kind='area', backend='plotly' )

plotly with wrong colors

1 Answer 1

2

It looks like some of the parameters don't have the same meaning depending on your plotting backend. color is one of them. When using plotly it tries to choose a dimension that will be used as color. The correct way is to use the color_discrete_map parameter:

df.plot(kind='area', 
        color_discrete_map={
            'Alfa': 'orange', 
            'Beta': 'lightslategray'}, 
        backend='plotly' )

Correctly plot

Unfortunately it won't be possible to interchange the backend engine.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.