python draw curves, draw subgraphs

Draw a curve

import matplotlib.pylab as pyl
import numpy as np
x = np.linspace(0.01, 3.5, 100, endpoint=True)
y = 1/x
x1=x
y1 = 2/x
x2=x
y2 = 3/x
fig = pyl.figure()
ax = fig.add_subplot(111)
ax.set_xlim(0,3.5) #设置图形的范围,默认为[0,1]
ax.set_ylim(0,3.5) #设置图形的范围,默认为[0,1]
ax.grid()  #添加网格
ax.set_aspect('equal')  #x轴和y轴等比例
pyl.plot(x,y)
pyl.plot(x1,y1)
pyl.plot(x2,y2)
pyl.xlabel('economics books')
pyl.ylabel('books about other subjects')
pyl.title('(d) indifferent curve')
pyl.annotate('increasing',xy=(2.5,2.5),xytext=(1.5,1.8),arrowprops=dict(arrowstyle="->",connectionstyle="arc3"))
pyl.show()

Draw a subgraph

import matplotlib.pylab as pyl
import numpy as np

#fig = pyl.figure(22)
fig = pyl.figure(dpi=500,figsize=(3,3))
ax = fig.add_subplot(331)
x = [0,1]
y = [1,0]
x1 = [0,2]
y1 = [2,0]
x2 = [0,3]
y2 = [3,0]
ax.set_xlim(0,3.5) #设置图形的范围,默认为[0,1]
ax.set_ylim(0,3.5) #设置图形的范围,默认为[0,1]
ax.grid()  #添加网格
ax.set_aspect('equal')  #x轴和y轴等比例
pyl.plot(x,y)
pyl.plot(x1,y1)
pyl.plot(x2,y2)
pyl.xlabel('economics books')
pyl.ylabel('books about other subjects')
pyl.title('indifferent curve')
pyl.annotate('increasing',xy=(2,2),xytext=(1,1.3),arrowprops=dict(arrowstyle="->",connectionstyle="arc3"))

ax = fig.add_subplot(333)
x = [0,3.5]
y = [0,3.5]
x1 = [0,2.5]
y1 = [1,3.5]
x2 = [1,3.5]
y2 = [0,2.5]
ax.set_xlim(0,3.5) #设置图形的范围,默认为[0,1]
ax.set_ylim(0,3.5) #设置图形的范围,默认为[0,1]
ax.grid()  #添加网格
ax.set_aspect('equal')  #x轴和y轴等比例
pyl.plot(x,y)
pyl.plot(x1,y1)
pyl.plot(x2,y2)
pyl.xlabel('economics books')
pyl.ylabel('books about other subjects')
pyl.title('indifferent curve')
pyl.annotate('increasing',xy=(0.5,3),xytext=(1.5,1.6),arrowprops=dict(arrowstyle="->",connectionstyle="arc3"))

ax = fig.add_subplot(337)
x = [1,1]
y = [0,3.5]
x1 = [2,2]
y1 = [0,3.5]
x2 = [3,3]
y2 = [0,3.5]
ax.set_xlim(0,3.5) #设置图形的范围,默认为[0,1]
ax.set_ylim(0,3.5) #设置图形的范围,默认为[0,1]
ax.grid()  #添加网格
ax.set_aspect('equal')  #x轴和y轴等比例
pyl.plot(x,y)
pyl.plot(x1,y1)
pyl.plot(x2,y2)
pyl.xlabel('economics books')
pyl.ylabel('books about other subjects')
pyl.title('indifferent curve')
pyl.annotate('increasing',xy=(3.5,1.5),xytext=(1.5,1.44),arrowprops=dict(arrowstyle="->",connectionstyle="arc3"))

ax = fig.add_subplot(339)
x = np.linspace(0.01, 3.5, 100, endpoint=True)
y = 1/x
x1=x
y1 = 2/x
x2=x
y2 = 3/x
ax.set_xlim(0,3.5) #设置图形的范围,默认为[0,1]
ax.set_ylim(0,3.5) #设置图形的范围,默认为[0,1]
ax.grid()  #添加网格
ax.set_aspect('equal')  #x轴和y轴等比例
pyl.plot(x,y)
pyl.plot(x1,y1)
pyl.plot(x2,y2)
pyl.xlabel('economics books')
pyl.ylabel('books about other subjects')
pyl.title('indifferent curve')
pyl.annotate('increasing',xy=(2.5,2.5),xytext=(1.5,1.8),arrowprops=dict(arrowstyle="->",connectionstyle="arc3"))
pyl.show()

Guess you like

Origin blog.csdn.net/qq_42830971/article/details/109289228