简体   繁体   English

Plotly Express - dataframe 列的 plot 子集默认情况下,Z65E8800B5C68002AAD8B6 为 F 选项

[英]Plotly Express - plot subset of dataframe columns by default and the rest as option

I am using plotly express to plot figures this way:我正在使用 plotly 快递到 plot 这样的数字:

    fig = px.line(df,
        x=df.index,
        y=df.columns
    )

It displays the graph properly and shows all the columns by default (as lines in the graph) with option to uncheck (or check) them to disable showing whatever we want if needed.它正确显示图表并默认显示所有列(作为图表中的线),并可选择取消选中(或选中)它们以禁用显示我们想要的任何内容(如果需要)。 What I would like is to show the same graph but by default uncheking some of the columns initially and keep the option to check or uncheck them for visualization.我想要显示相同的图表,但默认情况下最初取消选中某些列,并保留选中或取消选中它们以进行可视化的选项 This means that I cannot take only a subset of columns as new data frame to show as the other columns are still relevant.这意味着我不能只将列的子集作为新数据框来显示,因为其他列仍然相关。 Did not find anything in the documentation unfortunately...不幸的是,在文档中没有找到任何东西......

Thank you in advance.先感谢您。

You can use the visible property of the traces to state it is only in the legend.您可以使用迹线的visible属性到 state 它仅在图例中。 Below shows all columns in the figure then first two columns are set as visible, all other columns are only in the legend.下面显示了图中的所有列,然后前两列设置为可见,所有其他列仅在图例中。

import plotly.express as px
import pandas as pd
import numpy as np

# simulate dataframe
df = pd.DataFrame(
    {c: np.random.uniform(0, 1, 100) + cn for cn, c in enumerate("ABCDEF")}
)

fig = px.line(df, x=df.index, y=df.columns)

# for example only display first two columns of data frame, all others can be displayed
# by clicking on legend item
fig.for_each_trace(
    lambda t: t.update(visible=True if t.name in df.columns[:2] else "legendonly")
)

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 plotly 中绘制带有几列的数据框 - Plot dataframe w/ several columns in plotly 如何在 plotly 快递中的两个轴上 plot 多列? - How to plot multiple columns on both axis in plotly express? Plotly Express:使用 plotly express 将 dataframe 的各个列绘制为多个图(可滚动) - Plotly Express: Plotting individual columns of a dataframe as multiple plots (scrollable) using plotly express 在绘图上显示数据框 - Displaying a Dataframe on a plotly plot Plotly:如何在来自同一 Pandas 数据帧的不同列的一个绘图图表中绘制多条线? - Plotly: How to plot multiple lines in one plotly chart from different columns from the same pandas dataframe? 切片带有列子集的数据框 - Slicing dataframe with subset of columns DataFrame中列的子集上的逻辑OR - Logical OR on a subset of columns in a DataFrame Plotly:如何 plot 使用 plotly 和 Z26C592956DC26CA26AEF5DBACC204A03 回归线? - Plotly: How to plot a regression line using plotly and plotly express? Plotly Express: Plot Scatter MapBox with Feature Colors from DataFrame Column (px.scatter_mapbox) - Plotly Express: Plot Scatter MapBox with Feature Colors from DataFrame Column (px.scatter_mapbox) 当 Pandas 数据框包含数组而不是值时,是否可以使用 plotly express 为绘图设置动画? - Is it possible to animate a plot with plotly express when the pandas dataframe is containing arrays instead of values?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM