Giter Club home page Giter Club logo

Comments (12)

prateekshrivastav786 avatar prateekshrivastav786 commented on August 10, 2024 13

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

from plotly_express.

nicolaskruchten avatar nicolaskruchten commented on August 10, 2024 11

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

from plotly_express.

nicolaskruchten avatar nicolaskruchten commented on August 10, 2024 8

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()

from plotly_express.

nicolaskruchten avatar nicolaskruchten commented on August 10, 2024

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

from plotly_express.

mazzma12 avatar mazzma12 commented on August 10, 2024

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!

from plotly_express.

nicolaskruchten avatar nicolaskruchten commented on August 10, 2024

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

from plotly_express.

nicolaskruchten avatar nicolaskruchten commented on August 10, 2024

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.

from plotly_express.

tconnor23 avatar tconnor23 commented on August 10, 2024

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

from plotly_express.

nicolaskruchten avatar nicolaskruchten commented on August 10, 2024

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

from plotly_express.

anuraghuram avatar anuraghuram commented on August 10, 2024

Similarly, is there a way to hide the facet_col appearing as a header above subplots?

from plotly_express.

tabeacodes avatar tabeacodes commented on August 10, 2024

Hey, is there a way to set the x and y axis label for every subplot?

from plotly_express.

KeithWM avatar KeithWM commented on August 10, 2024

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()

This is a working solution of course, but it seems odd for this hack to be necessary.

from plotly_express.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.