Skip to content Skip to sidebar Skip to footer

How To Plot One Curve In Two Different Colors? (not Using Pandas)

I need to create a plot using matplotlib.pyplotthat shows distance between Earth and Mars over time. In addition to that some months e.g. March to August should be shown in a diffe

Solution 1:

The multicolored_line example looks like what you're going for.

Also see this article for more information about the colormap system in Matplotlib.

Solution 2:

Here is a simple one, just "overwrite" part where you want another color:

import matplotlib.pyplot as plt
%matplotlib inline
x = list(range(10))
y = [ 2*i for i in x]
x_1 = x[4:7]
y_1 = y[4:7]
plt.plot(x,y)
plt.plot(x_1,y_1)
plt.show()

Post a Comment for "How To Plot One Curve In Two Different Colors? (not Using Pandas)"