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?

1
  • You may want to add an MWE, as the code above requires data2 to be defined. Commented Oct 4, 2016 at 16:13

2 Answers 2

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') 
Sign up to request clarification or add additional context in comments.

Comments

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() 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.