How to plot graphs of functions

Useful tutorial:

Here is a python script:

#-*- coding: utf-8 -*-

import numpy as np
import matplotlib.pyplot as plt

X = np.linspace(-np.pi, np.pi, 256, endpoint=True)
C, S = np.cos(X), np.sin(X)

# Changing colors and line widths
plt.figure(figsize=(10, 6), dpi=80)
plt.plot(X, C, color="blue", linewidth=2.5, linestyle="-")
plt.plot(X, S, color="red",  linewidth=2.5, linestyle="-")

# Setting limits Current limits of the figure are a bit too tight 
# and we want to make some space in order to clearly see all data points.
plt.xlim(X.min() * 1.1, X.max() * 1.1)
plt.ylim(C.min() * 1.1, C.max() * 1.1)

# Setting ticks
plt.xticks([-np.pi, -np.pi/2, 0, np.pi/2, np.pi])
plt.yticks([-1, 0, +1])

# Moving spines
# Spines are the lines connecting the axis tick marks and noting the 
# boundaries of the data area. They can be placed at arbitrary positions 
# and until now, they were on the border of the axis. We’ll change that 
# since we want to have them in the middle. Since there are four of them 
# (top/bottom/left/right), we’ll discard the top and right by setting 
# their color to none and we’ll move the bottom and left ones to 
# coordinate 0 in data space coordinates.

ax = plt.gca()  # gca stands for 'get current axis'

# Setting tick labels: 
# Ticks are now properly placed but their label 
# is not very explicit. We could guess that 3.142 is π but it would be 
# better to make it explicit. When we set tick values, we can also 
# provide a corresponding label in the second argument list. 
# Note that we’ll use latex to allow for nice rendering of the label.
plt.xticks([-np.pi, -np.pi/2, 0, np.pi/2, np.pi],
                   [r'$-\pi$', r'$-\pi/2$', r'$0$', r'$+\pi/2$', r'$+\pi$'])
plt.yticks([-1, 0, +1],
                   [r'$-1$', r'', r'$+1$'])

plt.plot(X, C)
plt.plot(X, S)
                                                                                                                                                                                         1,1           Top

Was bei der Einbindung zu beachten ist:

Jedes Bild besteht aus mehreren Dokumenten. Dem generischen/ sprachunabhängigen (xxx.meta.xml) und je einem Paar (xxx.content_de.png, xxx_de.meta.xml und, xxx.meta_en.xml) von sprachabhängigen. In Artikeln wird der Link auf das generische eingetragen. Dann wird automatisch die richtige Sprache ausgewählt.

limits_sinxdurchx.png (18.1 KB) Tim Konopka, 04/26/2016 02:06 PM

limits_sinxdurchx.png (18.1 KB) Tim Konopka, 04/28/2016 02:09 PM

Limits_sinxdurchx Limits_sinxdurchx
Add picture from clipboard (Maximum size: 500 MB)