简体   繁体   English

如何 plot 多行在一个 plotly 图表中来自同一列的同一列 pandas Z6A8064B5DF47945550705553?

[英]How to plot multiple lines in one plotly chart from same column from the same pandas dataframe?

I have the following df as pandas:我有以下df作为pandas:

Name        X           Y              Location number

Ford        651536.216  4767758.137    250
Ford        651485.4353 4767685.615    161.4
Chevrolet   651536.791  4767758.958    251
Chevrolet   651542.525  4767767.147    261
Golf        651579.0758 4767819.347    324.7
Golf        651543.8153 4767768.99     263.2
Toyota      651579.0758 4767819.347    324.7
Toyota      651590.676  4767835.914    344.9
Renault     651513.011  4767674.872    26.97
Renault     651511.373  4767676.018    24.5
...

I have over hundred manufacturers name in a name column.我在名称列中有一百多个制造商名称。 I want to plot all the manufacturers in one plot using line chart.我想使用折线图将 plot 中的所有制造商放在一个 plot 中。

df_1 = df[df['Name'] == 'Ford']

df_2 = df[df['Name'] == 'Chevrolet']

df_3 = df[df['Name'] == 'Golf']

df_4 = df[df['Name'] == 'Toyota']

df_5 = df[df['Name'] == 'Renault']

I was able to achieve what I wanted by individually pointing manufacturers name from df and saving it to new df.通过从 df 单独指向制造商名称并将其保存到新的 df,我能够实现我想要的。

df_sorted1 = df_1.sort_values('Location number')
.
.
df_sorted6 = df_5.sort_values('Location number')

fig.add_trace(go.Scatter(x=df_1 ['x'], y=df_1 ['y'], mode='lines'))
fig.add_trace(go.Scatter(x=df_2 ['x'], y=df_2 ['y'], mode='lines'))
fig.add_trace(go.Scatter(x=df_3 ['x'], y=df_3 ['y'], mode='lines'))
fig.add_trace(go.Scatter(x=df_4 ['x'], y=df_4 ['y'], mode='lines'))
fig.add_trace(go.Scatter(x=df_5 ['x'], y=df_5 ['y'], mode='lines'))

What I want is to plot every manufacturers from one column.我想要的是 plot 从一列中的每个制造商。 X, Y is coordinates and location number is sorted because I want to start plotting from first location to latest X, Y 是坐标,位置编号已排序,因为我想从第一个位置开始绘制到最新位置

Try this code试试这个代码

df = df.sort_values(['Name', 'Location number'])

import plotly_express as px

px.line(df, x='X', y='Y', color='Name')

暂无
暂无

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

相关问题 Plotly:如何在来自同一 Pandas 数据帧的不同列的一个绘图图表中绘制多条线? - Plotly: How to plot multiple lines in one plotly chart from different columns from the same pandas dataframe? 使用 plotly 按结果从 pandas 组随时间将多条线绘制到同一个图表中 - Plot multiple lines into the same chart over time from pandas group by result using plotly Plotly 折线图来自 pandas dataframe 带多条线 - Plotly line chart from pandas dataframe with multiple lines Plot 列从不同的 dataframe 成一张线图 - Plot Column from different dataframe into one chart of lines 在同一张图表上将 Pandas DataFrame 绘制为条形图和折线图 - Plot Pandas DataFrame as Bar and Line on the same one chart Pandas - 从同一 dataframe 中的其他列中减去一列,用于具有不同列名和列数的多个文件 - Pandas - Subtract one column from other columns in same dataframe for multiple files with varying column names and number of columns 从pandas dataframe列中提取多个单词到同一列中 - Extracting multiple words from pandas dataframe column into same column 将同一行从 pandas dataframe 多次添加到新行,每次更改特定列中的值 - Add the same row multiple times from a pandas dataframe to a new one, each time altering a value in a specific column 从一个数据框中绘制多条线并添加辅助轴以绘制不同的数据框 - Pandas - Plotting multiple lines from one dataframe and adding a secondary axis to plot a different dataframe - Pandas 从熊猫数据框中绘制线 - Plot lines from pandas dataframe
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM