绘图点图 - 如何对多列进行分组

Plotly dot plot - how to group multiple columns

提问人:Loi Truong 提问时间:11/17/2023 最后编辑:Loi Truong 更新时间:11/17/2023 访问量:23

问:

我觉得我快要疯了,试图弄清楚这一点。假设我有这个数据框,我怎样才能创建一个类似于下图的点图?(只有点而不是条形)

ProbesetID 骨髓 骨髓
AFFX-r2-Bs-dap-3_at 120 250 221 150 332 242 400 130 432

请注意,如果列具有相同的名称,则点如何位于同一 x 轴上

理想的图表在这里

我尝试了绘图点图,但无法以某种方式将列组合在一起。

这是我的代码

import plotly.express as px
import plotly.graph_objects as go
  
# initialize list of lists 
data = [['ajfhf',120 , 250, 221 , 150 , 332, 242, 400, 130, 432]] 
  
# Create the pandas DataFrame 
df = pd.DataFrame(data, columns=['ProbeID', 'bone marrow' , 'bone marrow' ,'kidney' , 'kidney' ,'heart', 'heart' ,' heart' , 'lungs' ,'spleen']) 
cols = df.columns[1:]
print(cols)
fig = go.Figure()  
for col in cols:
    fig.add_trace(go.Scatter(
        y=df[col],
        name=col
    ))


fig.update_traces(marker_size=10)
fig.show()

这是它的样子。请注意它们是如何堆叠在 1 列上的,并且缺少一些点。在旅途中。分散部分,我不得不省略 x 轴,因为我不确定在那里使用什么。

我所拥有的

plotly plotly-dash plotly-python

评论


答: 暂无答案