import matplotlib.pyplot as plt import numpy as np import random from mpl_toolkits.mplot3d import Axes3D def f(x, y): return (1 - x / 2 + x ** 5 + y ** 3) * np.exp(-x **2 - y ** 2) n = 200 x = np.linspace(-3, 3, n) y = np.linspace(-3, 3, n) xgrid, ygrid = np.meshgrid(x, y) z = f(xgrid, ygrid) # f = plt.figure() # axes3d = Axes3D(f) # axes3d.plot_surface(xgrid, ygrid, z) Axes3D(plt.figure()).plot_surface(xgrid, ygrid, z, cmap="hot", rstride=10, cstride=10) plt.show() help(Axes3D(plt.figure()).plot_trisurf) exit() plt.contourf(z, 12, cmap="hot") plt.contour(z, 12, colors="black") plt.show() exit() n = 20 x = np.random.random_sample(n) print(x) plt.figure() random.seed(7) # colors = [(i / len(x), i % 2, 0) for i in range(len(x))] colors = [[random.random() for j in range(3)] for i in range(len(x))] # plt.pie(x, colors=colors) # plt.legend(colors) # plt.bar(x, x) plt.bar(range(n), x, width=1) plt.bar(range(n), -x, width=1, color=colors) plt.show() help(plt.bar) exit() x = np.linspace(0, 2) plt.figure() for i in range(4): # plt.axes([0.25 * i, 0.25 * i, 0.25, 0.25]) plt.axes([(i % 2) * 0.5 + 0.1, (1 - i // 2) * 0.5 + 0.1, 0.3, 0.3]) # plt.axes([(i % 2) * 0.5, (1 - i // 2) * 0.5, 0.5, 0.5]) y = x ** i plt.plot(x, y) plt.plot([1, 1, 0], [0, 1, 1], "--r", linewidth=3) plt.title("$y = x^" + str(i) + "$") plt.xlabel("x") plt.ylabel("y", verticalalignment="bottom") plt.ylim(0, 8) plt.show()