def _blank_plot(domain, ran): # make the plot fig = plt.figure(1) ax = SubplotZero(fig, 111) fig.add_subplot(ax) # thicken the axis lines ax.axhline(linewidth=1.7, color="k") ax.axvline(linewidth=1.7, color="k") x_lower, x_upper = int(domain.left), int( domain.right) # needs to be changed, is just a temporary type changer y_lower, y_upper = int(ran.left), int(ran.right) # remove tick lines on the axes plt.xticks([]) plt.yticks([]) plt.ylim(y_lower, y_upper) plt.xlim(x_lower, x_upper) # add axes labels ax.text(1.05, 0, r'$x$', transform=BlendedGenericTransform(ax.transAxes, ax.transData), va='center') ax.text(0, 1.05, r'$y$', transform=BlendedGenericTransform(ax.transData, ax.transAxes), ha='center') # end-of-axis arrows x_width = (abs(plt.xlim()[0]) + abs(plt.xlim()[1])) y_width = (abs(plt.ylim()[0]) + abs(plt.ylim()[1])) plt.arrow(plt.xlim()[1], -0.003, 0.00000000001, 0, width=x_width * 0.0015 * 0.5, color="k", clip_on=False, head_width=y_width * 0.12 / 7, head_length=x_width * 0.024 * 0.5) plt.arrow(0.003, plt.ylim()[1], 0, 0.00000000001, width=y_width * 0.0015 * 0.5, color="k", clip_on=False, head_width=x_width * 0.12 / 7, head_length=y_width * 0.024 * 0.5) # only show cartesian axes for direction in ["xzero", "yzero"]: ax.axis[direction].set_visible(True) for direction in ["left", "right", "bottom", "top"]: ax.axis[direction].set_visible(False)
def _blank_plot(domain, ran): # make the plot fig = plt.figure(1) ax = SubplotZero(fig, 111) fig.add_subplot(ax) # thicken the axis lines ax.axhline(linewidth=1.7, color="k") ax.axvline(linewidth=1.7, color="k") x_lower, x_upper = int(domain.left), int(domain.right) # needs to be changed, is just a temporary type changer y_lower, y_upper = int(ran.left), int(ran.right) # remove tick lines on the axes plt.xticks([]) plt.yticks([]) plt.ylim(y_lower, y_upper) plt.xlim(x_lower, x_upper) # add axes labels ax.text(1.05, 0, r'$x$', transform=BlendedGenericTransform(ax.transAxes, ax.transData), va='center') ax.text(0, 1.05, r'$y$', transform=BlendedGenericTransform(ax.transData, ax.transAxes), ha='center') # end-of-axis arrows x_width = (abs(plt.xlim()[0]) + abs(plt.xlim()[1])) y_width = (abs(plt.ylim()[0]) + abs(plt.ylim()[1])) plt.arrow(plt.xlim()[1], -0.003, 0.00000000001, 0, width=x_width*0.0015*0.5, color="k", clip_on=False, head_width=y_width*0.12/7, head_length=x_width*0.024*0.5) plt.arrow(0.003, plt.ylim()[1], 0, 0.00000000001, width=y_width*0.0015*0.5, color="k", clip_on=False, head_width=x_width*0.12/7, head_length=y_width*0.024*0.5) # only show cartesian axes for direction in ["xzero", "yzero"]: ax.axis[direction].set_visible(True) for direction in ["left", "right", "bottom", "top"]: ax.axis[direction].set_visible(False)
p = -3 # xの最小値 q = 3 # xの最大値 n = 12 # 引く包絡線の数 a_min = -10 # 表示させるaの最小値 a_max = 10 # 表示させるaの最大値 y_min = -6 # 表示させるbの最小値(最大値はa軸とb軸の縮尺が1:1になるよう自動で決まる) # アスペクト比を定めただけだと異常に縦長なグラフが出てくるのでylimを定めた y_max = y_min+a_max-a_min # これは変数ではない plt.figtext(0.85, 0.35, '$a$') # 直接位置を指定しているので、グラフの位置を変えるときにこれも変える plt.figtext(0.5, 0.95, '$b$') # ここより上に変数が入る fig = plt.figure(1) ax = SubplotZero(fig, 111) fig.add_subplot(ax) ax.axhline(linewidth=1.0, color="black") ax.axvline(linewidth=1.0, color="black") ax.set_xticks([]) # 空のlistを指定することでticksが入らない ax.set_yticks([]) ax.set(aspect=1) for direction in ["xzero", "yzero"]: ax.axis[direction].set_axisline_style("-|>") ax.axis[direction].set_visible(True) plt.ylim(ymin=y_min) # この位置より前に置くとx方向が狭くなってしまった plt.ylim(ymax=y_max) a = linspace(a_min, a_max, (a_max-a_min) * 10) # 点の数はaの動く範囲の長さ×10,これで曲線にも対応する # linspaceの点の数に小数が来ることがあり得るのですが、その場合は勝手に小数点以下を切り捨てた数の点をとってくれるようです for i in range(n): r = p+(q-p)*i/(n-1) # n個の接線を引き2個は両端にあるので区間はn-1等分される b = f(r, a) ax.plot(a, b, 'k', linewidth=0.5, alpha=1) # linewidth:線の太さ, alpha:濃さ(1以下), 黒色の線は'k'
from mpl_toolkits.axes_grid.axislines import SubplotZero from matplotlib.transforms import BlendedGenericTransform import matplotlib.pyplot as plt import numpy if 1: fig = plt.figure(1) ax = SubplotZero(fig, 111) fig.add_subplot(ax) ax.axhline(linewidth=1.7, color="black") ax.axvline(linewidth=1.7, color="black") plt.xticks(range(5)) plt.yticks(range(1,5)) ax.text(0, 1.05, '$x_{2}$', transform=BlendedGenericTransform(ax.transData, ax.transAxes), ha='center') ax.text(1.025, 0, '$x_{1}$', transform=BlendedGenericTransform(ax.transAxes, ax.transData), va='center') for direction in ["xzero", "yzero"]: ax.axis[direction].set_axisline_style("-|>") ax.axis[direction].set_visible(True) for direction in ["left", "right", "bottom", "top"]: ax.axis[direction].set_visible(False) x = numpy.linspace(-1, 3.5, 1000) y = (4 - 2*x) ax.plot(x,y) plt.annotate('$y=1$',xy=(1.75,1.5))