Skip to content
Advertisement

How to call multiple column of DataFrame on both axis for plot

My dataFrame has the following column, which shows pressure and corresponding volume measured for different samples, e.g. s_1p: pressure for sample-1 & s1_nv: corresponding volume for the same sample. I want to show all volume columns on the x-axis and pressure on the y-axis of the same plot (not sub-plot) and legend labelled as the sample number.

JavaScript

When I used the following code, it does the job.

JavaScript

But problem is that I have to call all the individual columns as a series and then again and again for the plot.

JavaScript

I want to automate the process so that I don’t have to call each individual column for the plot.
Any suggestion to plot the data in a single plot using seaborn or matplotlib

Advertisement

Answer

Starting from the dataframe you provided, the simplest way I am aware of drawing the plot you want is re-shape the dataframe in a proper way and then plot it.

Dataframe re-shaping

You need to re-shape your data in a dataframe with 3 columns: sample, pressure and volume. In order to do so, I save data in a new dataframe DF:

JavaScript
JavaScript

Complete Code

JavaScript

Plot

Now you can plot your data, for example you can use seaborn.scatterplot:

JavaScript

enter image description here

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement