This repository has been archived on 2021-05-17. You can view files and clone it, but cannot push or open issues or pull requests.
scientificComputing/resources/python/tutorial/05plotting2.py

29 lines
705 B
Python

from numpy import *
from matplotlib.pyplot import *
# create basepoints and function values
x = linspace(-2., 2., 100)
y = (x + 2.)**2 - 5.
y2 = (x + 1.)**2 + 2.3
fig = figure()
ax = fig.add_subplot(1,1,1)
# 1) additional parameters can either be specified in the correct
# order or via named parameters
#
# 2) If an r preceeds a string, the result is rendered from latex
#
# 3) Specifying the names argument "label" sets the label for a legend
#
ax.plot(x, y, color='r', linewidth=2, label=r'$(x+2)^2 - 5$')
ax.plot(x, y2, color='b', linewidth=2, label=r'$(x+1)^2 + 2.3$')
ax.set_xlabel('x values')
ax.set_ylabel(r'$f(x)$')
ax.set_title('quadratic function')
leg = ax.legend()
show() # show plot