图 13.10
import matplotlib.pyplot as plt import matplotlib as mpl import numpy as np mpl.rcParams["font.sans-serif"]=["SimHei"] mpl.rcParams["axes.unicode_minus"]=False fig, ax1 = plt.subplots() t=np.arange(0.05, 10.0, 0.01) s1=np.exp(t) ax1.plot(t, s1, c="b", ls="-") ax1.set_xlabel("x坐标轴") ax1.tick_params("y", colors="b") ax2=ax1.twinx() s2=np.cos(t**2) ax2.plot(t, s2, c="r", ls=":") ax2.set_ylabel("余弦函数", color="r") ax2.tick_params("y", colors="r") plt.show()
----------------------------------------------------------------------
图 13.11
import matplotlib.pyplot as plt import matplotlib as mpl import numpy as np mpl.rcParams["font.sans-serif"]=["SimHei"] mpl.rcParams["axes.unicode_minus"]=False fig, ax1 = plt.subplots() t=np.arange(0.05, 10.0, 0.01) s1=np.exp(t) ax1.plot(t, s1, c="b", ls="-") ax1.set_xlabel("x坐标轴") ax1.tick_params("y", colors="b") ax2=ax1.twinx() s2=np.cos(t**2) ax2.plot(t, s2, c="r", ls=":") ax2.set_ylabel("余弦函数", color="r") ax2.tick_params("y", colors="r") plt.savefig("C:\FIGURE_DEMO.png") plt.show()
----------------------------------------------------------------------