import numpy as np
from numpy import nan as NA
import matplotlib.pyplot as plt
fig=plt.figure()
ax1=fig.add_subplot(2,2,1)
# ax1.axis('off')
rect=plt.Rectangle((0.2,0.75),0.4,0.15,color='r')
ax1.add_patch(rect)
ax2=fig.add_subplot(222)
cir=plt.Circle((0.5,0.4),0.2,color='g',alpha=0.3)
ax2.add_patch(cir)
# ax2.axis('off')
ax3=fig.add_subplot(223)
pgon=plt.Polygon([(0.2,0.2),(0.35,0.25),(0.2,0.6)],color='b',alpha=0.9)
ax3.add_patch(pgon)
ax4=fig.add_subplot(224)
a=np.arange(10)
ax4.plot(a,a*1.5)
plt.show()
3d绘图
plt.rcParams['font.sans-serif'] = 'SimHei'
fig=plt.figure()
ax=fig.add_subplot(1,1,1,projection='3d')
def rand_range(n,rand_floor,rand_ceil):
rnd=np.random.rand(n)
print(rnd)
return (rand_ceil-rand_floor)*rnd+rand_floor
# x=rand_range(10,3,56)
# print(x)
# print('-----')
n=100
for zmin,zmax,c,m,l in [(4,15,'r','o','低值'),(13,40,'g','*','高值')]:
# print(zmin)
# print(zmax)
# print(c)
# print(m)
# print(l)
x=rand_range(n,0,20)
y=rand_range(n,0,20)
z=rand_range(n,zmin,zmax)
ax.scatter(x,y,z,c=c,marker=m,label=l,s=z*6)
ax.set_xlabel('X-VALUE')
ax.set_ylabel('Y-VALUE')
ax.set_title('3D散点图',size=10,weight='bold')
ax.legend(loc='upper left')
plt.show()