1

Is there a way to display a variable (specificaly, a linear fit paramter) in a plot I drow?

Also, is there a way to control the number of figures displayed?

I'm using matplotlib to generate the figures and optimize.curve_fit to do the curve fitting.

1
  • What do you mean by "control the number of figures displayed"? You're manually creating the figures... I guess I'm confused as to why you'd have more or less than the number of figures you want displayed? Commented Nov 26, 2011 at 22:40

1 Answer 1

3

Sure, just use text or annotate.

As a quick example:

import numpy as np
import matplotlib.pyplot as plt

# Generate data...
x = np.linspace(0, 30, 15)
y = 0.4 * x + 9 + np.random.random(x.size)

# Linear fit...
model = np.polyfit(x, y, deg=1)

plt.plot(x, y, 'bo', label='Observations')
plt.plot(x, model[0] * x + model[1], 'r-', label='Fitted Model')
plt.annotate(r'$y = {:.2f}x + {:.2f}$'.format(*model), xy=(0.1, 0.9), 
             xycoords='axes fraction', size=18)
plt.legend()

plt.show()

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.