fig.update_layout() does not iterate on all facets
See original GitHub issueI am trying to make a faceted plot where I need to treat the x axis as categorical, even though it is an integer. On a single chart (that is not faceted), the following works:
fig.update_layout(xaxis_type='category')
However, on a faceted chart, only one of the facets is changed. I would think that updating the figure layout would iterate on all facets.
Is there an an alternate way to do this using one of the fig.for_each_*() methods? (as in for_each_xaxis() . I played around with it but could not seem to find a way to do it.
Using plotly 4.6.0 on windows
Thanks
import pandas as pd
import plotly.express as px
df = pd.DataFrame({
'x': [1, 2, 3, 5, 6],
'y1': [1, 2, 3, 4, 5],
'y2': [10, 11, 12, 13, 15]
}).melt('x')
bars = px.bar(
data_frame=df,
x = 'x',
y = 'value',
facet_col = 'variable'
)
bars.update_layout(xaxis_type='category')
bars.show()
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Facet and trellis plots in Python - Plotly
Facet plots, also known as trellis plots or small multiples, are figures made up of multiple subplots which have the same set of...
Read more >Editing facet headings on a Plotly chart - Stack Overflow
So my graphs are printing out the correct data but for one of the graphs the axis does not match the hover text....
Read more >Python Plotly: How to set the range of the y axis?
Figure() function takes in data as input where we set the mode as ... Example 2: Using update_layout() function to set the y-axis...
Read more >Taking Another Look at Plotly - Practical Business Python
You did not have to post your visualizations to the Plotly servers but ... When I create visualizations, I iterate through many different ......
Read more >Visualization with Plotly.Express: Comprehensive guide
All plotly express charts can be done by one line of code. Image by author ... fig.update_layout(layout_parameters or add annotations)
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This is as intended:
layout.xaxis
refers to one x axis, andlayout.xaxis2
refers to the other. If you want to update all x axes, you can use.update_xaxes(type="category")
.Furthermore, you can use
.update_xaxes(row=1, col=2, type="category")
to target your update to a specific facet if you so choose, so you don’t really need to keep track ofxaxis
vsxaxis1
etc yourself if you choose not to 😃Yup
fig.update_xaxes(type='category')
, as documented here.Thanks for the posterity post!