From d39828ed699a43cf0a9062e0342000a68b2215d7 Mon Sep 17 00:00:00 2001 From: Emmanuelle Gouillart Date: Mon, 4 Nov 2019 17:27:03 -0500 Subject: [PATCH 1/2] added example about facet_col_wrap, and one example for disabling axis sharing --- python/facet-plots.md | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/python/facet-plots.md b/python/facet-plots.md index d7a282570..b495866df 100644 --- a/python/facet-plots.md +++ b/python/facet-plots.md @@ -20,7 +20,7 @@ jupyter: name: python nbconvert_exporter: python pygments_lexer: ipython3 - version: 3.6.7 + version: 3.7.3 plotly: description: How to make Facet and Trellis Plots in Python with Plotly. display_as: statistical @@ -58,6 +58,18 @@ fig = px.bar(tips, x="size", y="total_bill", color="sex", facet_row="smoker") fig.show() ``` +### Wrapping Column Facets + +When the facet dimension has a large number of unique values, it is possible to wrap columns using the `facet_col_wrap` argument. + +```python +import plotly.express as px +df = px.data.gapminder() +fig = px.scatter(df, x='gdpPercap', y='lifeExp', color='continent', size='pop', + facet_col='year', facet_col_wrap=4) +fig.show() +``` + ### Histogram Facet Grids ```python @@ -67,3 +79,20 @@ fig = px.histogram(tips, x="total_bill", y="tip", color="sex", facet_row="time", category_orders={"day": ["Thur", "Fri", "Sat", "Sun"], "time": ["Lunch", "Dinner"]}) fig.show() ``` + +### Facets with independent axes + +By default, facet axes are linked together: zooming inside one of the facets will also zoom in the other facets. You can disable this behaviour as follows. + +```python +import plotly.express as px +df = px.data.tips() +fig = px.scatter(df, x="total_bill", y="tip", color='sex', + facet_row="day", facet_col='time') +# No match between subplot axes +fig.update_xaxes(matches=None) +fig.update_yaxes(matches=None) +# Show ticks for each axis since they are now independent +fig.update_xaxes(showticklabels=True) +fig.show() +``` From 2b03f572e72214743c1d1aaba31a2116df7f0eee Mon Sep 17 00:00:00 2001 From: Nicolas Kruchten Date: Mon, 11 Nov 2019 21:11:30 -0500 Subject: [PATCH 2/2] unmatched facet warning --- python/facet-plots.md | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/python/facet-plots.md b/python/facet-plots.md index b495866df..17d3a0f50 100644 --- a/python/facet-plots.md +++ b/python/facet-plots.md @@ -20,7 +20,7 @@ jupyter: name: python nbconvert_exporter: python pygments_lexer: ipython3 - version: 3.7.3 + version: 3.6.8 plotly: description: How to make Facet and Trellis Plots in Python with Plotly. display_as: statistical @@ -82,17 +82,24 @@ fig.show() ### Facets with independent axes -By default, facet axes are linked together: zooming inside one of the facets will also zoom in the other facets. You can disable this behaviour as follows. +By default, facet axes are linked together: zooming inside one of the facets will also zoom in the other facets. You can disable this behaviour when you use `facet_row` only, by disabling `matches` on the Y axes, or when using `facet_col` only, by disabling `matches` on the X axes. It is not recommended to use this approach when using `facet_row` and `facet_col` together, as in this case it becomes very hard to understand the labelling of axes and grid lines. ```python import plotly.express as px df = px.data.tips() -fig = px.scatter(df, x="total_bill", y="tip", color='sex', - facet_row="day", facet_col='time') -# No match between subplot axes -fig.update_xaxes(matches=None) +fig = px.scatter(df, x="total_bill", y="tip", color='sex', facet_row="day") fig.update_yaxes(matches=None) -# Show ticks for each axis since they are now independent -fig.update_xaxes(showticklabels=True) fig.show() ``` + +```python +import plotly.express as px +df = px.data.tips() +fig = px.scatter(df, x="total_bill", y="tip", color='sex', facet_col="day") +fig.update_xaxes(matches=None) +fig.show() +``` + +```python + +```