Comments (12)
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
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
from plotly_express.
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:
from plotly_express.
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.
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.
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.
You could of course use this to edit any property etc.
from plotly_express.
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.
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
from plotly_express.
@jdamiba can you add this example to the facet docs please? ☝️
from plotly_express.
Similarly, is there a way to hide the facet_col appearing as a header above subplots?
from plotly_express.
Hey, is there a way to set the x and y axis label for every subplot?
from plotly_express.
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)
- Marginal subplots disappear when selecting another frame HOT 1
- range_theta in polar plots would be nice HOT 2
- `category_orders` does not raise an error with incorrect column name HOT 3
- ImportError: cannot import name 'ensure_writable_plotly_dir' HOT 1
- plotly.express does not interact properly with panel in jupyter notebook HOT 4
- TypeError: imshow() got an unexpected keyword argument 'x' HOT 4
- Plotly Express shows blank plot for chloropleths on virtual machine! Error: 404 GET/static/plotly.js! how to resolve this?
- Facet Grids with Overlay Lines HOT 1
- Argument for plots to become non-interactive to save memory in Jupyter HOT 1
- Image export ignores layout for plot size (using )
- Density Contour range_z
- plotly loop in loop HOT 1
- How to use countplot() in plotly with VAEX data frame? HOT 9
- Using px.density_contour with both marginal_x and contours_coloring causes error HOT 2
- Fill between two vertical lines but multiple times
- Adding bar traces with add_trace gives different x-axis spacing than adding strip or box traces
- Not working with IPython
- plotly express shows Invalid property latitude for choropleth map plot
- Wrong y-values when using bar graph HOT 1
- Error occured while creating the select button. HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from plotly_express.