How to plot graphs of functions¶
Useful tutorial: https://matplotlib.org/api/colors_api.html
Here are some python scripts:
Sinus x durch x
#-*- 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' ax.spines['right'].set_color('none') ax.spines['top'].set_color('none') ax.xaxis.set_ticks_position('bottom') ax.spines['bottom'].set_position(('data',0)) ax.yaxis.set_ticks_position('left') ax.spines['left'].set_position(('data',0)) # 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) plt.show() 1,1 Top
Log und exp
#-*- coding: utf-8 -*- # Figure size before plot import matplotlib.pyplot as plt import numpy as np # Definitionsbereich t = np.arange(-4, 4, 0.001) # Funktionendeklaration n = np.log(10) ex, ln = np.exp(t), np.log(t) pot, lg10 = np.exp(t*n), np.log10(t) plt.figure(figsize=(10, 10), dpi=100) # Set x limits plt.xlim(-4.0, 4.0) # Set y limits plt.ylim(-4, 4) # Ticks plt.xticks([-1,0,1]) plt.yticks([-1,0,1]) # Beschriftung der Achsen plt.xlabel("x") plt.ylabel("y", rotation='horizontal') plt.axhline(0, color='black') plt.axvline(0, color='black') plt.plot(t, ln, color="blue", linewidth=2.0, linestyle="-" , label="$Nat\ddot{u}rlicher \, Logarithmus$ ") plt.plot(t, lg10, color="red" , linewidth=2.0, linestyle="-" , label="$Dekadischer Logrithmus$ ") plt.plot(t, ex, color="blue", linewidth=2.0, linestyle="dashed" , label="$\mathrm{\,\mathbb{R}}$ ") plt.legend(loc='lower right') # Moving spines ax = plt.gca() # gca stands for 'get current axis' ax.spines['right'].set_color('none') ax.spines['top'].set_color('none') ax.xaxis.set_ticks_position('bottom') ax.spines['bottom'].set_position(('data',0)) ax.yaxis.set_ticks_position('left') ax.spines['left'].set_position(('data',0)) # Setting tick labels: plt.xticks([-1, 0, 1], [-1, r'' , +1]) plt.yticks([-1, 0, +1], [-1, r'' , +1]) # Title plt.title(r' $Logarithmus \, und \, Exponentialfunktion$') #plt.title(r'$\ddot{o}\acute{e}\grave{e}\hat{O}\breve{i}\bar{A}\tilde{n}\vec{q}$', fontsize=20) plt.grid(True) plt.savefig("exp-log_de.png") plt.show()
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.content_en.de, xxx.meta_en.xml) von sprachabhängigen. In Artikeln wird der Link auf das generische eingetragen. Dann wird automatisch die richtige Sprache ausgewählt.