%matplotlib notebook
import numpy as np
import matplotlib.pyplot as plt
a = [1, 2, 3, 4]
b = [3, 2, 0, 1]
fig = plt.figure(1) # erzeugt ein Fenster fuer Graphik
ax = fig.add_subplot(111) # 'ax' ist das Koordinatensystem
ax.plot(a, b,'x');
bb = np.interp(2.5, a, b)
ax.plot(2.5, bb, 'rd');
aas = np.array([2.5, 2.6, 2.7])
bbs = np.interp(aas, a, b)
ax.plot(aas, bbs, 'mp');
ax.set_xlim([1, 3])
ax.set_xlabel('x Achse')
ax.set_ylabel('meine Funktion')
ax.axis([-1, 4, 0, 5]);
x und y Achse vertauscht
fig = plt.figure(2)
plt.plot(b, a)
x = np.arange(1000) + 1;
y = np.log(x);
fig = plt.figure()
plt.plot(x, y);
fig = plt.figure(3)
ax = plt.axes(xlabel="x", ylabel="y", title="Log Funktion")
ax.title.set_fontsize(20);
ax.xaxis.label.set_fontweight("bold");
ax.yaxis.label.set_fontstyle("italic");
ax.semilogx(x, y);
y = x**3.3
plt.figure(13)
plt.axes(xlabel="x", ylabel="y", title="Potenz Funktion")
plt.loglog(x,y)
# Alternativ
plt.figure(111)
plt.xlabel("x")
plt.ylabel("y")
plt.title("Potenz Funktion",fontsize=20)
plt.xticks(fontsize=20)
plt.loglog(x,y);
tiere = ["Frösche", "Igel", "Hunde", "Katzen" ];
anzahlen = [15, 30, 45, 10 ];
farben = ["yellow", "gold", "blue", "coral" ];
fig = plt.figure(20)
plt.pie(anzahlen, labels=tiere, colors=farben, shadow=True,
startangle=90, explode=[ 0, 0, 0, 0.5 ]);
plt.axis("equal");
plt.figure(30)
dreieck = [[0,0], [1,0], [0,1], [0,0]]
plt.plot([0,1,0,0], [0,0,1,0])
plt.axis(xmin=-.01,ymin=-.01);
plt.figure(31)
dreieck = [[0,0], [1,0], [0,1], [0,0]]
plt.fill([0,1,0,0], [0,0,1,0],color='red')
plt.axis(xmin=-.01,ymin=-.01);
x = np.linspace(0,1.8*np.pi)
y1 = np.sin(x)
y2 = np.cos(x)
plt.figure(32)
plt.fill(x,y1)
plt.plot(x,y1,'xr')
#plt.fill(y1,y2,'r')
#plt.plot(y1,y2,'co')
plt.axis('equal')
from mpl_toolkits.mplot3d import Axes3D
from itertools import product, combinations
fig = plt.figure(100)
ax = fig.add_subplot(111, projection='3d')
phi = np.linspace(0,2*np.pi,20).reshape(-1,1)
theta = np.linspace(0,np.pi,20).reshape(1,-1)
x = np.cos(phi) * np.sin(theta)
y = np.sin(phi) * np.sin(theta)
z = np.ones_like(phi) * np.cos(theta)
ax.plot3D(x.flatten(),y.flatten(),z.flatten(),'r')
my_col = plt.cm.hsv((x+1)/2)
ax.plot_surface(x,y,z,facecolors=my_col)
#Wuerfel
r = [-1, 1]
for s, e in combinations(np.array(list(product(r,r,r))), 2):
if np.sum(np.abs(s-e)) == r[1]-r[0]:
ax.plot3D(*zip(s,e), color="b")
ax.set_aspect('equal')
Was passiert bei der Konstruktion des Würfels?
[xx for xx in product(r,r,r)]
[xx for xx in combinations( [1,2,3],2)]
[xx for xx in zip((-1, -1, -1), (1, 2, 3))]
xx = [*zip((-1, -1, -1), (1, 2, 3))]
xx