Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider removing column name and = sign in legend #36

Closed
mazzma12 opened this issue Mar 29, 2019 · 9 comments
Closed

Consider removing column name and = sign in legend #36

mazzma12 opened this issue Mar 29, 2019 · 9 comments

Comments

@mazzma12
Copy link

@mazzma12 mazzma12 commented Mar 29, 2019

Hi again @nicolaskruchten,

Something that puzzled me about the color arg in the plot is that it includes the name of the column followed by an equal sign. Would you consider removing it and just let the value of the column in place? Here are a few reasons to support that point :

  • It is not displayed in plotly by default
  • It's redundant information when we see date= orcountry= it easy to infer by the value of the field
  • It takes some extra place, that is valuable, especially in the vertical orientation.

image

Also, for personal taste, I think equal sign does not play well outside equations and prefer : instead.

Happy to discuss with you about it. Maybe there is an option that can disable it, that I am not aware of.

@mazzma12 mazzma12 changed the title Consider removing attribute name and = sign in legend Consider removing column name and = sign in legend Mar 29, 2019
@nicolaskruchten

This comment has been minimized.

Copy link
Member

@nicolaskruchten nicolaskruchten commented Mar 29, 2019

Thanks for the input!

This is the best compromise I could find at the moment for dealing with cases where in fact it's not easy to infer from the value (i.e. the values are "Yes" and "No" and the column is called "Smoker" etc) and because when you are using colours and symbols, you need to be able to differentiate which is which ("smoker=Yes, child=Yes" vs "Yes, Yes").

The best way to deal wit this would be to have separate legends for color, symbol, size and line-dash, with titles, but plotly.js doesn't (yet) support this kind of thing.

In terms of how to actually get the effect you want, unfortunately you'll have to iterate through the traces and change the names. We're looking at various ways to make that easier: plotly/plotly.py#1484

@mazzma12

This comment has been minimized.

Copy link
Author

@mazzma12 mazzma12 commented Apr 5, 2019

Hi @nicolaskruchten eventually I found the time to reply!

This is the best compromise I could find at the moment for dealing with cases where in fact it's not easy to infer from the value (i.e. the values are "Yes" and "No" and the column is called "Smoker" etc) and because when you are using colours and symbols, you need to be able to differentiate which is which ("smoker=Yes, child=Yes" vs "Yes, Yes").

From my experience, such ambiguity would be limited as the graph would come with a title s.a evolution by smoking behaviour. But I hadn't realized you could have composed categories, in this case, I understand that might be tricky.

The best way to deal wit this would be to have separate legends for color, symbol, size and line-dash, with titles, but plotly.js doesn't (yet) support this kind of thing.
Do you mean having a title for each legend section like in theseaborn API for categorical data? I think that was the reference I had in mind when opening the issue, too bad!

@nicolaskruchten

This comment has been minimized.

Copy link
Member

@nicolaskruchten nicolaskruchten commented May 7, 2019

With the newest release, you can now easily change this after the fact with something like:

.for_each_trace(lambda t: t.update(name=t.name.replace("=",": ")))

For example:

image

@nicolaskruchten

This comment has been minimized.

Copy link
Member

@nicolaskruchten nicolaskruchten commented May 7, 2019

You could of course use this to edit any property etc.

@prateekshrivastav786

This comment has been minimized.

Copy link

@prateekshrivastav786 prateekshrivastav786 commented Feb 19, 2020

If you just want to show the values in legend, you can use this:

fig = px.scatter(data_grouped_month, x="resolved_tf", y="alert_role",
                 size='incident_count',color='alert_role', hover_data=['alert_role']).for_each_trace(lambda t: t.update(name=t.name.split("=")[1]))

like if you have something like:

alert_role=cpu
alert_role=clone
alert_role=memory
alert_role=io wait time
alert_role= databse

Like:
Screenshot 2020-02-19 at 12 39 27

so the below snippet will remove the "alert_role" and will show only values like cpu, clone,memory etc:
.for_each_trace(lambda t: t.update(name=t.name.split("=")[1]))

The output will be:

cpu
clone
memory
io wait time
database

Screenshot 2020-02-19 at 12 31 58

@nicolaskruchten

This comment has been minimized.

Copy link
Member

@nicolaskruchten nicolaskruchten commented Feb 19, 2020

This is actually no longer necessary... As of Plotly.py 4.5, Plotly Express no longer puts the = in trace names, because legends support titles.

@tconnor23

This comment has been minimized.

Copy link

@tconnor23 tconnor23 commented Feb 21, 2020

Love the update to the legend in 4.5! Now I'm wondering if there's a way to supress the '=' expression from the titles of sub-plots. or if not, is there a helper function like there used to be for traces, something like:

for_each_subplot( lambda z: z.update(title=z.title[(z.title.find("=")+1):]))

i.e. want to remove the highlighted part
image

@nicolaskruchten

This comment has been minimized.

Copy link
Member

@nicolaskruchten nicolaskruchten commented Feb 21, 2020

Yep:

import plotly.express as px

fig = px.scatter(px.data.tips(), x="total_bill", y="tip", facet_col="smoker")
fig.for_each_annotation(lambda a: a.update(text=a.text.split("=")[-1]))
fig.show()
@nicolaskruchten

This comment has been minimized.

Copy link
Member

@nicolaskruchten nicolaskruchten commented Feb 21, 2020

@jdamiba can you add this example to the facet docs please? ☝️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.