简体   繁体   English

带 Dash/Plotly 的分类散点图 Plot

[英]Categorical Scatter Plot with Dash/Plotly

I am trying to make a categorical scatter plot like this:我正在尝试像这样制作分类散点图 plot:

离散位置(井)与时间点中的元素计数

This is supposed to be a categorical scatter plot with discrete x values represented by counts of elements in locations(Wells) vs Time Point.这应该是一个分类散点图 plot,其离散 x 值由位置(井)与时间点中的元素计数表示。

I have written this code:我写了这段代码:

df = pd.read_excel (r'file.xlsx')

fig = go.Figure()
fig.add_trace(
  go.Scatter(
    x = [df['Well A'], df['Well B'],df['Well C'],df['Well D']],
    y = df['Time Point'],
    mode='markers'
  )
)

And I get this as a result:结果我得到了这个:

结果

Which is crazy, I have no idea what is even happening there.这太疯狂了,我什至不知道那里发生了什么。 Could you please help?..能否请你帮忙?..

PS My df looks like this: PS 我的 df 看起来像这样:

数据集

Please, help:(请帮忙:(

If this is your desired result:如果这是您想要的结果:

在此处输入图像描述

for c in df.columns[1:]:
    fig.add_trace(go.Scatter(x = df['Time Point'], y = df[c],
                             mode = 'markers',
                             name = c
                            )
                 )

Complete code:完整代码:

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

obs = 8
df = pd.DataFrame({'Time Point': [1,2,3,4,5,6,7,8],
                   'Well A':np.random.randint(10, size=8),
                   'Well B':np.random.randint(10, size=8),
                   'Well C':np.random.randint(10, size=8),
                   'Well D':np.random.randint(10, size=8)})

fig = go.Figure()
for c in df.columns[1:]:
    fig.add_trace(go.Scatter(x = df['Time Point'], y = df[c],
                             mode = 'markers',
                             name = c
                            )
                 )
fig.show()

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

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