简体   繁体   English

使用分类 X 绘制散点图而不组合常见的 X 值

[英]Plot scatter with categorical X without combining common X values

Hi I have a large dataset, and using add_trace I want to have a graph that shows a1,a1, and b1 as their x values, but default run of Scatter plot uses one a1 x for both y, how can I make the plot like this: The graph I want嗨,我有一个大数据集,并且使用 add_trace 我想要一个图表,将 a1、a1 和 b1 显示为它们的 x 值,但是散点图的默认运行对两个 y 都使用一个 a1 x,我怎样才能使图像这个:我想要的图表

This is the code I have which gave me a different graph with common a1这是我拥有的代码,它给了我一个不同的图形,带有常见的 a1

import pandas as pd
import plotly
import plotly.graph_objects as go
df=pd.DataFrame({'a':('a1','a1', 'b1'), 'b': (1,2,3)})
fig = go.Figure()
fig.add_trace(go.Scatter(x=df['a'], y=df['b']))

This not the graph I want这不是我想要的图表

use the dataframe index as the x values and column a as the text for the ticks使用数据框索引作为 x 值和列a作为刻度的文本

import pandas as pd
import plotly
import plotly.graph_objects as go
df=pd.DataFrame({'a':('a1','a1', 'b1'), 'b': (1,2,3)})
fig = go.Figure()
fig.add_trace(go.Scatter(x=df.index, y=df['b']))

fig.update_layout(
    xaxis = dict(
        tickmode = 'array',
        tickvals = df.index,
        ticktext = df["a"]
    )
)

在此处输入图片说明

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM