【Python百日进阶-数据分析】Day145 - plotly小提琴图:px.violin()语法

一、语法

在小提琴图中,data_frame行被组合成一个弯曲的标记,以可视化它们的分布。

plotly.express.violin(data_frame=None, 
                      x=None, 
                      y=None, 
                      color=None, 
                      facet_row=None, 
                      facet_col=None, 
                      facet_col_wrap=0, 
                      facet_row_spacing=None, 
                      facet_col_spacing=None, 
                      hover_name=None, 
                      hover_data=None, 
                      custom_data=None, 
                      animation_frame=None, 
                      animation_group=None, 
                      category_orders=None, 
                      labels=None, 
                      color_discrete_sequence=None, 
                      color_discrete_map=None, 
                      orientation=None, 
                      violinmode=None, 
                      log_x=False, 
                      log_y=False, 
                      range_x=None, 
                      range_y=None, 
                      points=None, 
                      box=False, 
                      title=None, 
                      template=None, 
                      width=None, 
                      height=None)

二、参数

  • data_frame ( DataFrame或类似数组的或dict ) – 需要传递此参数才能使用列名(而不是关键字名)。Array-like 和 dict 在内部转换为 pandas DataFrame。可选:如果缺少,则使用其他参数在后台构建 DataFrame。

  • x ( str或int或Series或array-like ) – 中的列名data_frame,或者 pandas Series 或 array_like 对象。此列或 array_like 中的值用于在笛卡尔坐标中沿 x 轴定位标记。或者可以是列引用列表或 array_likes 列表,在这种情况下,数据将被视为“宽”而不是“长” x。 y

  • y(str或int或Series或array-like)– 中的列名data_frame,或者 pandas Series 或 array_like 对象。此列或 array_like 中的值用于在笛卡尔坐标中沿 y 轴定位标记。或者可以是列引用列表或 array_likes 列表,在这种情况下,数据将被视为“宽”而不是“长” x。 y

  • color(str或int或Series或array-like)– 中的列名data_frame,或者 pandas Series 或 array_like 对象。此列或 array_like 中的值用于为标记分配颜色。

  • facet_row ( str或int或Series或array-like ) – 中的列名data_frame,或者 pandas Series 或 array_like 对象。此列或 array_like 中的值用于在垂直方向上为多面子图分配标记。

  • facet_col ( str或int或Series或array-like ) – 中的列名data_frame,或者 pandas Series 或 array_like 对象。此列或 array_like 中的值用于在水平方向上为多面子图分配标记。

  • facet_col_wrap ( int ) – 最大分面列数。以该宽度包装列变量,以便列分面跨越多行。如果为 0,则忽略,如果设置facet_row了或 a ,marginal则强制为 0。

  • facet_row_spacing ( float between 0 and 1 ) – 分面行之间的间距,以纸张为单位。使用 facet_col_wrap 时,默认值为 0.03 或 0.0.7。

  • facet_col_spacing ( float between 0 and 1 ) – 分面列之间的间距,以纸张为单位默认为 0.02。

  • hover_name(str或int或Series或array-like)- 中的列名data_frame,或者 pandas Series 或 array_like 对象。此列或 array_like 中的值在悬停工具提示中以粗体显示。

  • hover_data ( list of str or int , or Series or array-like , or dict ) – 或者 pandas Series 中的列名列表data_frame,或者是 array_like 对象或者以列名作为键的 dict,值为 True (默认为格式)False(为了从悬停信息中删除此列)或格式字符串,例如 ‘:.3f’ 或 ’ | %a’ 或类似列表的数据出现在悬停工具提示中,或带有布尔或格式化字符串的元组作为第一个元素,以及类似列表的数据作为第二个元素出现在悬停中 这些列中的值在悬停工具提示中显示为额外数据.

  • custom_data(str或int的列表,或Series或类似数组)——data_frame或 pandas Series 或 array_like 对象中的列名称这些列中的值是额外数据,例如用于小部件或 Dash 回调。此数据对用户不可见,但包含在图形发出的事件中(套索选择等)

  • animation_frame ( str或int或Series或array-like ) – 中列的名称data_frame,或者 pandas Series 或 array_like 对象。此列或 array_like 中的值用于为动画帧分配标记。

  • animation_group ( str或int或Series或array-like ) – 中的列名data_frame,或者 pandas Series 或 array_like 对象。此列或 array_like 中的值用于提供跨动画帧的对象恒定性:具有匹配 animation_group 的行将被视为描述每个帧中的相同对象。

  • category_orders(带有 str 键和 str 值列表的字典(默认{}))——默认情况下,在 Python 3.6+ 中,轴、图例和构面中的分类值的顺序取决于这些值第一次遇到的顺序data_frame(并且没有在低于 3.6 的 Python 中默认保证顺序)。此参数用于强制对每列的值进行特定排序。此 dict 的键应对应于列名,值应是与所需的特定显示顺序相对应的字符串列表。

  • labels(带有 str 键和 str 值的字典(默认{}))——默认情况下,列名在图中用于轴标题、图例条目和悬停。这个参数允许它被覆盖。此 dict 的键应对应于列名,值应对应于要显示的所需标签。

  • color_discrete_sequence ( list of str ) – 字符串应该定义有效的 CSS 颜色。当color设置为 且对应列中的值不是数字时,该列中的值通过color_discrete_sequence 按 中描述的顺序循环分配颜色category_orders,除非 的值 color是 中的键color_discrete_map。子模块中提供了各种有用的颜色序列plotly.express.colors,特别是plotly.express.colors.qualitative.

  • color_discrete_map (dict with str keys and str values (default {})) – 字符串值应该定义有效的 CSS-colors 用于覆盖 color_discrete_sequence以将特定颜色分配给与特定值对应的标记。中的键color_discrete_map应该是由 表示的列中的值color。或者,如果 的值color是有效颜色,则’identity’可以传递字符串以直接使用它们。

  • orientation(str,‘h’水平或’v’垂直之一。) - (默认’v’如果提供 和x并且y都连续或都分类,否则’v’('h' )是分类和 )是连续的,否则提供'h' )) if x(yy(x’v’() if only x(y

  • violinmode (str (default ‘group’)) – 一种’group’或’overlay’在’overlay’模式中,小提琴被绘制在另一个之上。在’group’模式中,小提琴并排放置。

  • log_x (boolean (default False)) – 如果True是,x 轴在笛卡尔坐标中按对数缩放。

  • log_y (boolean (default False)) – 如果True是,y 轴在笛卡尔坐标中按对数缩放。

  • range_x (两个数字的列表) – 如果提供,则覆盖笛卡尔坐标中 x 轴上的自动缩放。

  • range_y (两个数字的列表) – 如果提供,则覆盖笛卡尔坐标中 y 轴上的自动缩放。

  • points (str or boolean (default ‘outliers’)) – ‘outliers’、‘suspectedoutliers’、‘all’或中的一个False。如果 ‘outliers’,则仅显示位于晶须之外的样本点。如果’suspectedoutliers’,则显示所有异常点,并且那些小于 4Q1-3Q3 或大于 4Q3-3Q1 的点用标记的 突出显示’outliercolor’。如果’outliers’,则仅显示位于晶须之外的样本点。如果’all’,则显示所有样本点。如果False,则不显示样本点,并且晶须延伸到样本的整个范围。

  • box (boolean (default False)) – 如果True是,则在小提琴内部绘制框。

  • title ( str ) – 图形标题。

  • template(str或dict或plotly.graph_objects.layout.Template 实例)–图形模板名称(必须是 plotly.io.templates 中的键)或定义。

  • width (int (default None)) – 图形宽度(以像素为单位)。

  • height (int (default None)) – 以像素为单位的图形高度。

  • data_frame (DataFrame or array-like or dict) – This argument needs to be passed for column names (and not keyword names) to be used. Array-like and dict are tranformed internally to a pandas DataFrame. Optional: if missing, a DataFrame gets constructed under the hood using the other arguments.

  • x (str or int or Series or array-like) – Either a name of a column in data_frame, or a pandas Series or array_like object. Values from this column or array_like are used to position marks along the x axis in cartesian coordinates. Either x or y can optionally be a list of column references or array_likes, in which case the data will be treated as if it were ‘wide’ rather than ‘long’.

  • y (str or int or Series or array-like) – Either a name of a column in data_frame, or a pandas Series or array_like object. Values from this column or array_like are used to position marks along the y axis in cartesian coordinates. Either x or y can optionally be a list of column references or array_likes, in which case the data will be treated as if it were ‘wide’ rather than ‘long’.

  • color (str or int or Series or array-like) – Either a name of a column in data_frame, or a pandas Series or array_like object. Values from this column or array_like are used to assign color to marks.

  • facet_row (str or int or Series or array-like) – Either a name of a column in data_frame, or a pandas Series or array_like object. Values from this column or array_like are used to assign marks to facetted subplots in the vertical direction.

  • facet_col (str or int or Series or array-like) – Either a name of a column in data_frame, or a pandas Series or array_like object. Values from this column or array_like are used to assign marks to facetted subplots in the horizontal direction.

  • facet_col_wrap (int) – Maximum number of facet columns. Wraps the column variable at this width, so that the column facets span multiple rows. Ignored if 0, and forced to 0 if facet_row or a marginal is set.

  • facet_row_spacing (float between 0 and 1) – Spacing between facet rows, in paper units. Default is 0.03 or 0.0.7 when facet_col_wrap is used.

  • facet_col_spacing (float between 0 and 1) – Spacing between facet columns, in paper units Default is 0.02.

  • hover_name (str or int or Series or array-like) – Either a name of a column in data_frame, or a pandas Series or array_like object. Values from this column or array_like appear in bold in the hover tooltip.

  • hover_data (list of str or int, or Series or array-like, or dict) – Either a list of names of columns in data_frame, or pandas Series, or array_like objects or a dict with column names as keys, with values True (for default formatting) False (in order to remove this column from hover information), or a formatting string, for example ‘:.3f’ or ‘|%a’ or list-like data to appear in the hover tooltip or tuples with a bool or formatting string as first element, and list-like data to appear in hover as second element Values from these columns appear as extra data in the hover tooltip.

  • custom_data (list of str or int, or Series or array-like) – Either names of columns in data_frame, or pandas Series, or array_like objects Values from these columns are extra data, to be used in widgets or Dash callbacks for example. This data is not user-visible but is included in events emitted by the figure (lasso selection etc.)

  • animation_frame (str or int or Series or array-like) – Either a name of a column in data_frame, or a pandas Series or array_like object. Values from this column or array_like are used to assign marks to animation frames.

  • animation_group (str or int or Series or array-like) – Either a name of a column in data_frame, or a pandas Series or array_like object. Values from this column or array_like are used to provide object-constancy across animation frames: rows with matching animation_groups will be treated as if they describe the same object in each frame.

  • category_orders (dict with str keys and list of str values (default {})) – By default, in Python 3.6+, the order of categorical values in axes, legends and facets depends on the order in which these values are first encountered in data_frame (and no order is guaranteed by default in Python below 3.6). This parameter is used to force a specific ordering of values per column. The keys of this dict should correspond to column names, and the values should be lists of strings corresponding to the specific display order desired.

  • labels (dict with str keys and str values (default {})) – By default, column names are used in the figure for axis titles, legend entries and hovers. This parameter allows this to be overridden. The keys of this dict should correspond to column names, and the values should correspond to the desired label to be displayed.

  • color_discrete_sequence (list of str) – Strings should define valid CSS-colors. When color is set and the values in the corresponding column are not numeric, values in that column are assigned colors by cycling through color_discrete_sequence in the order described in category_orders, unless the value of color is a key in color_discrete_map. Various useful color sequences are available in the plotly.express.colors submodules, specifically plotly.express.colors.qualitative.

  • color_discrete_map (dict with str keys and str values (default {})) – String values should define valid CSS-colors Used to override color_discrete_sequence to assign a specific colors to marks corresponding with specific values. Keys in color_discrete_map should be values in the column denoted by color. Alternatively, if the values of color are valid colors, the string ‘identity’ may be passed to cause them to be used directly.

  • orientation (str, one of ‘h’ for horizontal or ‘v’ for vertical.) – (default ‘v’ if x and y are provided and both continous or both categorical, otherwise ‘v’(‘h’) if x(y) is categorical and y(x) is continuous, otherwise ‘v’(‘h’) if only x(y) is provided)

  • violinmode (str (default ‘group’)) – One of ‘group’ or ‘overlay’ In ‘overlay’ mode, violins are on drawn top of one another. In ‘group’ mode, violins are placed beside each other.

  • log_x (boolean (default False)) – If True, the x-axis is log-scaled in cartesian coordinates.

  • log_y (boolean (default False)) – If True, the y-axis is log-scaled in cartesian coordinates.

  • range_x (list of two numbers) – If provided, overrides auto-scaling on the x-axis in cartesian coordinates.

  • range_y (list of two numbers) – If provided, overrides auto-scaling on the y-axis in cartesian coordinates.

  • points (str or boolean (default ‘outliers’)) – One of ‘outliers’, ‘suspectedoutliers’, ‘all’, or False. If ‘outliers’, only the sample points lying outside the whiskers are shown. If ‘suspectedoutliers’, all outlier points are shown and those less than 4Q1-3Q3 or greater than 4Q3-3Q1 are highlighted with the marker’s ‘outliercolor’. If ‘outliers’, only the sample points lying outside the whiskers are shown. If ‘all’, all sample points are shown. If False, no sample points are shown and the whiskers extend to the full range of the sample.

  • box (boolean (default False)) – If True, boxes are drawn inside the violins.

  • title (str) – The figure title.

  • template (str or dict or plotly.graph_objects.layout.Template instance) – The figure template name (must be a key in plotly.io.templates) or definition.

  • width (int (default None)) – The figure width in pixels.

  • height (int (default None)) – The figure height in pixels.

三、返回值

plotly.graph_objects.Figure

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

岳涛@心馨电脑

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值