0

Could somebody help me to fix the fact that my code is correctly plotting the first curve but not the second one ? Instructions are the same though...

from numpy import loadtxt
from pylab import *

res_1 = loadtxt("channel_2.txt", skiprows=1)
res_2 = loadtxt("corr_channel_2.txt", skiprows=1)

plot(res_1[:, 0], res_1[:, 1])
plt.subplot(2, 1, 1)  # plot original data above
plot(res_2[:, 0], res_2[:, 1])
plt.subplot(2, 1, 2)  # plot corrected data below
plt.show()

enter image description here

Thank you

гиви
  • 79
  • 7
  • 3
    Invert the order of plot and subplot: subplot, plot original, subplot, plot corrected – gboffi Apr 15 '21 at 20:50
  • 4
    Even better, use the object oriented approach: `fig, (ax1, ax2) = plt.subplots(2, 1) ; ax1.plot(original) ; ax2.plot(corrected)` – gboffi Apr 15 '21 at 20:52
  • Thank you to you both – гиви Apr 15 '21 at 21:03
  • You're welcome, but I'm only one… – gboffi Apr 15 '21 at 21:23
  • 3
    Please don't use `pylab`. And certainly don't `import *`. Use `from matplotlib import pyplot as plt`. See [What is the difference between pylab and pyplot?](https://stackoverflow.com/questions/11469336/what-is-the-difference-between-pylab-and-pyplot#:~:text=From%20the%20documentation%2C%20the%20emphasis,underlying%20plotting%20library%20in%20matplotlib.) – JohanC Apr 15 '21 at 22:30

0 Answers0