plotly.py icon indicating copy to clipboard operation
plotly.py copied to clipboard

Fix Issue 2966 px.pie has no legend title

Open lucafs opened this issue 4 years ago • 0 comments

Code PR

  • [X] I have read through the contributing notes and understand the structure of the package. In particular, if my PR modifies code of plotly.graph_objects, my modifications concern the codegen files and not generated files.
  • [X] I have added tests (if submitting a new feature or correcting a bug) or modified existing tests.
  • [ ] I have added a CHANGELOG entry if fixing/changing/adding anything substantial.

Fixes #2966 issue and adds a new testing file to test changes asserting that the name in the parameter "names" is the same as fig.layout.legend.title.text in the fig variable.

Example

Code:

import plotly.express as px
df = px.data.gapminder().query("year == 2007").query("continent == 'Europe'")
df.loc[df['pop'] < 2.e6, 'country'] = 'Other countries' # Represent only large countries
fig = px.pie(df, values='pop', names='country', title='Population of European continent')
fig.show()

Results

Before: image

After: image

lucafs avatar Dec 09 '21 01:12 lucafs