Drawing lines in different colors


User 8491020
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np

df1 = pd.DataFrame(np.random.randint(0,15,size=(15, 1)))
df2 = pd.DataFrame(np.random.randint(20,35,size=(10, 1)))


frames = [df1, df2]
result = pd.DataFrame(pd.concat(frames))

df3 = result.cumsum()
df3 = df3.reset_index(drop=False)
print(df3)
df3.plot(y=0)
plt.show()

Is it possible to draw df3 lines with two different colors? The first color is used for rows 0 to 14, and the second color is used for rows 15 to 24. Somehow I want to mark where df1 ends and df2 begins.

alive

about what

#[...]
df3 = result.cumsum()
df3 = df3.reset_index(drop=False)
plt.plot(df3.mask(df3.apply(lambda x: x.index < 15))[0], color='blue')
plt.plot(df3.mask(df3.apply(lambda x: x.index > 15))[0], color='green')
plt.show()
plt.close()# do not forget this to save you from Runtime Error.

enter image description here

Related


Drawing lines in different colors

User 8491020 import pandas as pd import matplotlib.pyplot as plt import numpy as np df1 = pd.DataFrame(np.random.randint(0,15,size=(15, 1))) df2 = pd.DataFrame(np.random.randint(20,35,size=(10, 1))) frames = [df1, df2] result = pd.DataFrame(pd.concat(frames

Drawing lines in different colors

User 8491020 import pandas as pd import matplotlib.pyplot as plt import numpy as np df1 = pd.DataFrame(np.random.randint(0,15,size=(15, 1))) df2 = pd.DataFrame(np.random.randint(20,35,size=(10, 1))) frames = [df1, df2] result = pd.DataFrame(pd.concat(frames

Drawing lines in different colors

User 8491020 import pandas as pd import matplotlib.pyplot as plt import numpy as np df1 = pd.DataFrame(np.random.randint(0,15,size=(15, 1))) df2 = pd.DataFrame(np.random.randint(20,35,size=(10, 1))) frames = [df1, df2] result = pd.DataFrame(pd.concat(frames

Drawing lines with different colors using WebGL

User 4726090 I am trying to plot points so use gl.drawArrays(gl.LINE_STRIP, 0, points.length); Connecting the points together will give me a complete shape, maybe a polygon. The problem is with the points drawn, the lines are broken. I understand the differe

Drawing lines with different colors using WebGL

User 4726090 I am trying to plot points so use gl.drawArrays(gl.LINE_STRIP, 0, points.length); Connecting the points together will give me a complete shape, maybe a polygon. The problem is with the points drawn, the lines are broken. I understand the differe

AmCharts - Lines of Different Colors

username I need to use the line as a different color between bullets in the same graph, i.e. if the line is going up (from smaller value bullet to larger value item) it needs to be green; if the line is down , it needs to be red. One option I found for AmChart

Animate lines of different colors

math world I am trying to animate data for a demo. I am trying to use python's animation package to do so. What I'm trying to do roughly boils down to the first example in http://jakevdp.github.io/blog/2012/08/18/matplotlib-animation-tutorial/ import numpy as

Drawing circles of different colors with python

Suraj For the generated set of points, How can I draw circles with different colors at each point? How can I display the center point of the circle even though the circle is filled? Purpose: I have a set of GPS points and I want to draw a line through these po

Drawing circles of different colors with python

Suraj For the generated set of points, How can I draw circles with different colors at each point? How can I display the center point of the circle even though the circle is filled? Purpose: I have a set of GPS points and I want to draw a line through these po

Drawing circles of different colors with python

Suraj For the generated set of points, How can I draw circles with different colors at each point? How can I display the center point of the circle even though the circle is filled? Purpose: I have a set of GPS points and I want to draw a line through these po

Drawing circles of different colors with python

Suraj For the generated set of points, How can I draw circles with different colors at each point? How can I display the center point of the circle even though the circle is filled? Purpose: I have a set of GPS points and I want to draw a line through these po