Home > OS >  how to draw multi line color in python
how to draw multi line color in python

Time:12-23

i have problem, i want to draw multi line color diagram in python, i don't know how can i do that, my data frame like this:

frame  |  name     |  color  | max_val

0      |  sadness  |   c     |   0.07

24     |  sadness  |   c     |   0.054

48     |  neutral  |   k     |   0.8

etc..

my script is:

 enomy = {
"anger":"r",
"disgust":"g",
"fear":"m",
"happiness":"y",
"sadness":"c",
"surprise":"b",
"neutral":"k",
}
x = df["Max_value"]
y = df["frame"]
z = []
for i in range(len(x)):
    z.append(enomy[list(df["name"])[i]])

fig, ax = plt.subplots()
for j in range(len(x)):
    plt.plot(y, x, color=z[j])

plt.show()

and this plot is like that: enter image description here

how i can solve this and draw multi line plot?

CodePudding user response:

The problem seems to be that you are drawing the whole set of lines each time with a new color inside for j. A simple solution is draw one part of the whole curve each time, for example:

for j in range(len(x)-1):
    plt.plot(y[j:j 2], x[j:j 2], color=z[j])

(I can't be sure if you want the color of each line to be associated with the start or end point. The above code colors each line according to the starting frame.)

  • Related