0

I spent many hours looking for tips how to create categorical plot using Seaborn and Pandas having several Xs to be added on x-axis, but I have not found the solution.

For specified columns from excel (for example: S1_1, S1_2, S1_3) I would like to create one scatterplot with readings - it means for each column header 9 measurements are expected. Please refer to the image to see the data structure in excel. I was unable to find the right function.

I tried with the following code, but this is not what I wanted to achieve.

import pandas as pd import matplotlib.pyplot as plt import seaborn as sns df = pd.read_excel("panda.xlsx") dfx = pd.DataFrame({"CHAR": ["S1_1","S1_2","S1_3"]}) sns.stripplot(x=dfx['CHAR'],y=df['S1_1'],color='black') sns.stripplot(x=dfx['CHAR'],y=df['S1_2'],color='black') sns.stripplot(x=dfx['CHAR'],y=df['S1_3'],color='black') plt.xlabel('X Axis') plt.ylabel('Y Axis') plt.show() 

Expected vs obtained plot:

expected vs obtained plot

4
  • 1
    1. Including an image of the results of your code would help. 2. What do you want to be different? Commented Dec 29, 2022 at 20:34
  • @The Photon, I have uploaded the outcome and the sketch what is expected under the link: i.sstatic.net/3NEsp.png Commented Dec 29, 2022 at 20:53
  • So you want 9 dots above each x-axis label? Commented Dec 29, 2022 at 20:57
  • Yes, this is exactly what I am looking for. I have been looking for similar example for hours. Commented Dec 29, 2022 at 20:59

1 Answer 1

1

You're overthinking things. You don't need to call stripplot separately for each column. I generated new random data since you didn't share yours in a copy-and-pastable form, but stripplot will basically do what I think you want with a very short invocation.

> print(df) S1 S2 S3 S4 0 0.314097 0.678525 0.228356 0.770293 1 0.207790 0.739484 0.965662 0.604426 2 0.975562 0.959384 0.088162 0.265529 3 0.616823 0.902795 0.015561 0.662020 4 0.210507 0.287713 0.660347 0.763312 5 0.763505 0.381314 0.759422 0.257578 6 0.707832 0.912063 0.774681 0.534284 7 0.996891 0.258103 0.313047 0.729142 8 0.121308 0.797310 0.286265 0.757299 > sns.stripplot(data=df[["S1", "S2", "S3"]], color='black') > plt.xlabel("X Axis") 

enter image description here

Sign up to request clarification or add additional context in comments.

1 Comment

Right, much simpler than I thought. Powerfull tool. It was my first post on this site I did not expect to get the answer so quickly. Really appreciate your support, thank you!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.