Skip to content

fig.update_layout() does not iterate on all facets #2545

@rsgoodwin

Description

@rsgoodwin

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

2020-06-05_19-45-25

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions