Search code examples
pythonpandasmatplotlibplotlyseaborn

Plot pandas all columns from and use their dataframe


I would like to have every column on my x-Axis and every value on my y-Axis. With plotly and seaborn I could only find a way to plot the values against each other (column 1 on x vs coulmn 2 on y). So for my shown example following would be columns: "Import Files", "Defining Variables", "Simulate Cutting Down",... I would like to have all theri values on the y-Axis. enter image description here So what I basically want is

import matplotlib.pyplot as plt
import pandas as pd
df = pd.read_csv('timings.csv')
df.T.plot()
plt.show()

but with scatter. Matplotlib, Seaborn or Plotly is fine by me.

This would be an example for a csv File, since I can't upload a file:

Import Files,Defining Variables,Copy All Cutters,Simulate Cutting Down,Calculalte Circle, Simulate Cutting Circle, Calculate Unbalance,Write to CSV,Total Time
0.015956878662109375,0.0009989738464355469,0.022938966751098633,0.1466083526611328,0.0009968280792236328,48.128061294555664,0.0,0.014995098114013672,48.33055639266968
0.015958786010742188,0.0,0.024958133697509766,0.14598894119262695,0.0,49.22848296165466,0.0,0.004987239837646484,49.42037606239319
0.015943288803100586,0.0,0.036900997161865234,0.14561033248901367,0.0,46.80884146690369,0.0,0.004009723663330078,47.011305809020996

Solution

  • I only used the data you provided; as mentioned by others in the comments, barplot is more suited for this data but here it is with scatter plot:

    import pandas as pd 
    import seaborn as sns 
    import matplotlib.pyplot as plt 
    
    fig, ax = plt.subplots(figsize=(16,5))
    sns.scatterplot(data=df.melt(), x='variable', y ='value', ax=ax)
    ax.set_xlabel('')
    ax.set_ylabel('Time in seconds')
    

    enter image description here