1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
|
import numpy as np import matplotlib import matplotlib.pyplot as plt import matplotlib.font_manager as fm from mpl_toolkits.mplot3d import Axes3D
myfont = fm.FontProperties(fname="simsun.ttc", size=14) matplotlib.rcParams["axes.unicode_minus"] = False
def simple_plot(): """ simple plot """ plt.figure(figsize=(8, 6), dpi=80)
plt.ion()
for index in range(10): plt.cla()
plt.title("动态曲线图", fontproperties=myfont) plt.grid(True)
x = np.linspace(-np.pi + 0.1*index, np.pi+0.1*index, 256, endpoint=True) y_cos, y_sin = np.cos(x), np.sin(x)
plt.xlabel("X轴", fontproperties=myfont) plt.xlim(-4 + 0.1*index, 4 + 0.1*index) plt.xticks(np.linspace(-4 + 0.1*index, 4+0.1*index, 9, endpoint=True))
plt.ylabel("Y轴", fontproperties=myfont) plt.ylim(-1.0, 1.0) plt.yticks(np.linspace(-1, 1, 9, endpoint=True))
plt.plot(x, y_cos, "b--", linewidth=2.0, label="cos示例") plt.plot(x, y_sin, "g-", linewidth=2.0, label="sin示例")
plt.legend(loc="upper left", prop=myfont, shadow=True)
plt.pause(0.1)
plt.ioff() plt.show() return
simple_plot()
|