plotly.figure_factory
.create_facet_grid¶
-
plotly.figure_factory.
create_facet_grid
(df, x=None, y=None, facet_row=None, facet_col=None, color_name=None, colormap=None, color_is_cat=False, facet_row_labels=None, facet_col_labels=None, height=None, width=None, trace_type='scatter', scales='fixed', dtick_x=None, dtick_y=None, show_boxes=True, ggplot2=False, binsize=1, **kwargs)¶ Returns figure for facet grid; this function is deprecated, since plotly.express functions should be used instead, for example
>>> import plotly.express as px >>> tips = px.data.tips() >>> fig = px.scatter(tips, ... x='total_bill', ... y='tip', ... facet_row='sex', ... facet_col='smoker', ... color='size')
- Parameters
df ((pd.DataFrame)) – the dataframe of columns for the facet grid.
x ((str)) – the name of the dataframe column for the x axis data.
y ((str)) – the name of the dataframe column for the y axis data.
facet_row ((str)) – the name of the dataframe column that is used to facet the grid into row panels.
facet_col ((str)) – the name of the dataframe column that is used to facet the grid into column panels.
color_name ((str)) – the name of your dataframe column that will function as the colormap variable.
colormap ((str|list|dict)) – the param that determines how the color_name column colors the data. If the dataframe contains numeric data, then a dictionary of colors will group the data categorically while a Plotly Colorscale name or a custom colorscale will treat it numerically. To learn more about colors and types of colormap, run
help(plotly.colors)
.color_is_cat ((bool)) –
determines whether a numerical column for the colormap will be treated as categorical (True) or sequential (False).
Default = False.
facet_row_labels ((str|dict)) – set to either ‘name’ or a dictionary of all the unique values in the faceting row mapped to some text to show up in the label annotations. If None, labeling works like usual.
facet_col_labels ((str|dict)) – set to either ‘name’ or a dictionary of all the values in the faceting row mapped to some text to show up in the label annotations. If None, labeling works like usual.
height ((int)) – the height of the facet grid figure.
width ((int)) – the width of the facet grid figure.
trace_type ((str)) – decides the type of plot to appear in the facet grid. The options are ‘scatter’, ‘scattergl’, ‘histogram’, ‘bar’, and ‘box’. Default = ‘scatter’.
scales ((str)) – determines if axes have fixed ranges or not. Valid settings are ‘fixed’ (all axes fixed), ‘free_x’ (x axis free only), ‘free_y’ (y axis free only) or ‘free’ (both axes free).
dtick_x ((float)) – determines the distance between each tick on the x-axis. Default is None which means dtick_x is set automatically.
dtick_y ((float)) – determines the distance between each tick on the y-axis. Default is None which means dtick_y is set automatically.
show_boxes ((bool)) – draws grey boxes behind the facet titles.
ggplot2 ((bool)) – draws the facet grid in the style of
ggplot2
. See http://ggplot2.tidyverse.org/reference/facet_grid.html for reference. Default = Falsebinsize ((int)) – groups all data into bins of a given length.
kwargs ((dict)) – a dictionary of scatterplot arguments.
Examples 1: One Way Faceting
>>> import plotly.figure_factory as ff >>> import pandas as pd >>> mpg = pd.read_table('https://raw.githubusercontent.com/plotly/datasets/master/mpg_2017.txt')
>>> fig = ff.create_facet_grid( ... mpg, ... x='displ', ... y='cty', ... facet_col='cyl', ... ) >>> fig.show()
Example 2: Two Way Faceting
>>> import plotly.figure_factory as ff
>>> import pandas as pd
>>> mpg = pd.read_table('https://raw.githubusercontent.com/plotly/datasets/master/mpg_2017.txt')
>>> fig = ff.create_facet_grid( ... mpg, ... x='displ', ... y='cty', ... facet_row='drv', ... facet_col='cyl', ... ) >>> fig.show()
Example 3: Categorical Coloring
>>> import plotly.figure_factory as ff >>> import pandas as pd >>> mtcars = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/mtcars.csv') >>> mtcars.cyl = mtcars.cyl.astype(str) >>> fig = ff.create_facet_grid( ... mtcars, ... x='mpg', ... y='wt', ... facet_col='cyl', ... color_name='cyl', ... color_is_cat=True, ... ) >>> fig.show()