[英]Categorical Scatter Plot with Plotly
I am trying to draw a scatter plot with numerical x-values that are discrete.我正在尝试使用离散的数字 x 值绘制散点图 plot。 The problem is that
Plotly
interprets the values as continuous and the resulting dots are not evenly spaced.问题是
Plotly
将这些值解释为连续的,并且结果点的间距不均匀。 In Seaborn
I could solve this problem by converting the x-values to str
, but this doesn't work in Plotly
.在
Seaborn
我可以通过将 x 值转换为str
来解决这个问题,但这在Plotly
中不起作用。 Any solutions?有什么解决办法吗? MWE below:
MWE如下:
4489058292 0.60
4600724046 0.26
6102975308 0.19
6122589624 0.10
4467367136 1.67
6008680375 2.50
4588967207 0.21
4941295226 0.34
4866979526 0.18
4906915418 0.38
test_df = pd.read_clipboard(sep="\s+", names=["ID", "Value"], index_col=0)
fig = px.scatter(
test_df,
x=test_df.index.astype(str),
y=test_df,
)
fig.update_layout(showlegend=False)
IIUC, in the update_layout
, you can specify the xaxis_type
to be category
like: IIUC,在
update_layout
中,您可以将xaxis_type
指定为如下category
:
fig = px.scatter(
test_df,
x=test_df.index, #no need of str here
y=test_df,
)
fig.update_layout(showlegend=False,
xaxis_type='category') #add this
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.