Python Forum

Full Version: How to plot vertically stacked plot with same x-axis and
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi,

I have below data:

Inputdata.csv:

Name   Date      y1   y2  y3
VAB    20190601  1    0   0
VAB    20190603  1    1   0
VLKA   20190604  0    0   1
MAKY   20190604  1    1   1
VAB    20190605  1    0   0
VAB    20190606  1    1   1
MAKY   20190609  0    1   1
I want group by name and plot Date Vs. y1,y2,y2 (y1, y2, y3 are in vertically stacked)

import pandas as pd
input=r'D:\PythonCodes\Inputdata.csv'

df=pd.read_csv(input)
x=df['Date']
y1=df['y1']
y2=df['y2']
y3=df['y3']

fig, axs = plt.subplots(3, sharex=True, sharey=True)
fig.suptitle('Sharing both axes')
axs[0].plot(x, y1)
axs[1].plot(x, y2, 'o')
axs[2].plot(x, y3, '+')
But I want to group the chart automatically based on "Name", and plot in vertically stacked plots.