0

I have this code :

x = np.linspace(data2.X.min(), data2.X.max(), 100) 
f = 0.1 + (0.2 * x)
fig, ax = plt.subplots(figsize=(12,8))
ax.plot(x, f, 'r', label='Prediction #1')
ax.scatter(data2.X, data2.Y, label='Raw Data') 
ax.legend(loc=2)  
ax.set_xlabel('X') 
ax.set_ylabel('Y')
plt.show()

The above code creates this plot: Plot

I want to add one more linear function named "Prediction #2" with blue/green line color. How do I do this?

BrechtDeMan
  • 6,589
  • 4
  • 24
  • 25
Dendi Handian
  • 348
  • 2
  • 12
  • You may want to add an [MWE](http://stackoverflow.com/help/mcve), as the code above requires `data2` to be defined. – BrechtDeMan Oct 04 '16 at 16:13

2 Answers2

1

You can add new plots to the same axes and set their colors (see other color options in documentation):

...
ax.plot(blue_x, blue_f, 'b', label='Prediction Blue')
ax.plot(green_x, green_f, 'g', label='Prediction Green')
berna1111
  • 1,811
  • 1
  • 18
  • 23
0

Here's another line in blue:

x = np.linspace(0, 100, 100) 
f = 0.1 + (0.2 * x)
f2 = 0.2 + (0.3 * x)
fig, ax = plt.subplots(figsize=(12,8))
ax.plot(x, f, 'r', label='Prediction #1')
ax.plot(x, f2, 'b', label='Prediction #2')
ax.scatter(data2.X, data2.Y, label='Raw Data') 
ax.legend(loc=2)  
ax.set_xlabel('X') 
ax.set_ylabel('Y')
plt.show()
JMat
  • 752
  • 6
  • 14