I feel like I’m going crazy trying to figure this out. Supposedly I have this data frame, how can I create a dot plot similar to the graph below? (just the dots and not the bars)
ProbesetID
bone marrow
bone marrow
kidney
kidney
heart
heart
heart
lungs
spleen
AFFX-r2-Bs-dap-3_at
120
250
221
150
332
242
400
130
432
Notice how the dots are in the same x-axis if the columns have the same name
I tried plotly dot plot but haven’t been able to somehow group the columns together.
This is my code
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 = px.scatter(df, y="nation", x="count", color="medal", symbol="medal")
fig.update_traces(marker_size=10)
fig.show()
Here is what it looked like. Notice how they’re all stacked on 1 column and some dots are missing. In the go.Scatter part, I had to leave out x axis because I wasn’t sure what to use there.
@hoatran So I ended up with something similar to your graph. I got rid of the for loop, and assigned the column names to x, and values to y. But thanks to you I discovered the melt method. I’ll look more into this because I do need to group the tissues into different tissue groups.
I do have a follow-up question if you don’t mind. Is there a way for plotly to distinctly show grouped columns? The graph below is what I’m trying to achieve. Notice how the tissues in each tissue group are wrapped inside a box and there’s spacing between them.
I read the subplot documentation (especially this part Subplots in Python (plotly.com) ) but it seems like subplots are each own separate entity. In the graph I shared, the whole thing seems like a big plot, or at least everything inside looks connected; instead of separate entities like subplots.
Hey no worries, I really appreciate your help. Your comment above helps me figure out how to make the bar chart subplot. I’m still not sure how to group the tissues together like in the screenshot I sent (For example: Heart is part of cardiovascular system, and Osteoclast is part of Connective tissue; so there are some spacing between them. The same goes for every tissue in Digestive system: Liver, stomach, large intestines…). But I’ll see what I can do