Home > Back-end >  Problem when adding a third line to subplot
Problem when adding a third line to subplot

Time:07-08

I need to create subplots that represents 3 variables (line plots) in each one, but the problem is that when i add the third one, the subplot goes wrong (the line is displayed wrong). This doesnt happen when i include only x and two variables.

In this example, the first subplot is ok with the variables x , y1 y2, but when i add y3 it goes wrong. x, y1, y2, and y3 are columns of a data frame where x is 01, 02, 03 and 04 and the others are values for those months. Thanks

# Subplot 1
#axis[0, 0].plot(x, y1, y2, y3) #WORKS WRONG WHEN ADDING Y3

CodePudding user response:

You need to repeat the x in the call to plot:

ax.plot(x, y1, x, y2, x, y3)

or repeatedly call plot on the same axes object:

for y in (y1, y2, y3):
    ax.plot(x, y)

See Plotting multiple sets of data in the docs for plot.

  • Related