Search code examples
pythonplotlylegendlinechartlegend-properties

How can I fix this legend labels issue in plotly (Python)?


Heres the code for Line Plot with column encoding color from website: plotly.

import plotly.express as px

df = px.data.gapminder().query("continent=='Oceania'")
fig = px.line(df, x="year", y="lifeExp", color='country')
fig.show()

My output legend label varies from the site please the below images :

Website Image result Website Image

My Image Outputenter image description here

Could any one help me, to fix this legend label issue with equal sign and the get the desired output as the first image. At present it look weird for my original data as it has more than 10 categories for a column and facing this legend problem is in each type of graph.


Solution

  • This is due to version differences of plotly.

    To fix the same, you can:

    • Upgrade plotly on Google Colab or Jupyter Notebook: !pip install --upgrade plotly
    • Upgrade plotly on your system or Terminal: pip install --upgrade plotly

    The Version 5.1.0 supports the required configuration.

    To Install a specific version of plotly, you can use the command: pip install plotly==5.1.0