GCGM
GCGM

Reputation: 1073

Plot panda df with two variables

I have the following dataframes dfS1 and dfS2:

dfS1
                 var1      var2       var3
Intensity0 -19.318328 -3.074213  -9.178206
Intensity1 -18.784095 -3.757662 -10.017049
Intensity2 -17.720688 -4.144756 -10.912899

dfS2
                var1      var2      var3
Amplitude0 -0.146261  0.017926  0.412654
Amplitude1 -0.853830  0.081825  0.402913
Amplitude2 -0.476011  0.067459  0.265233

I manage to plot them idependently by using a simple dfS1.plot()

enter image description here

and dfS2.plot()

enter image description here

My objective is to arrange the two df in such way that the two pltos are combined and if possible, plot the lines of one of the df with a different style (I am thinking about dash-line but the same colorus as var1, var2 and var3 are common).

Upvotes: 0

Views: 47

Answers (1)

koPytok
koPytok

Reputation: 3713

You should explicitly specify axes. It can be achieved using plt.subplots. For dashed lines you simply need to add parameter style="--", and to reset color sequence use plt.gca().set_prop_cycle(None). To specify limits on Y axis use plt.ylim(low, high).

The code is as follows:

import matplotlib.pylab as plt

fig, ax = plt.subplots()
dfS1.plot(style="--", ax=ax)

plt.gca().set_prop_cycle(None)
dfS2.plot(ax=ax)

plt.ylim(-1, 1)

Upvotes: 1

Related Questions