雷达图
绘制空白极地图
import matplotlib. pyplot as plt
plt. polar( )
plt. show( )
绘制一个极坐标点
import numpy as np
import matplotlib. pyplot as plt
plt. polar( 0.25 * np. pi, 20 , 'ro' , lw= 2 )
plt. ylim( 0 , 50 )
plt. show( )
绘制多个极坐标点
import numpy as np
import matplotlib. pyplot as plt
theta= np. array( [ 0.25 , 0.45 , 0.65 , 0.75 , 1 , 1.35 , 1.65 , 2 ] )
r= [ 60 , 70 , 80 , 40 , 70 , 80 , 75 , 65 ]
plt. polar( theta* np. pi, r, 'ro' , lw= 2 )
plt. ylim( 0 , 100 )
plt. show( )
极坐标连线闭合
import numpy as np
import matplotlib. pyplot as plt
theta= np. array( [ 0.25 , 0.45 , 0.65 , 0.75 , 1 , 1.35 , 1.65 , 2 , 0.25 ] )
r= [ 60 , 70 , 80 , 40 , 70 , 80 , 75 , 65 , 60 ]
plt. polar( theta* np. pi, r, 'ro-' , lw= 2 )
plt. ylim( 0 , 100 )
plt. show( )
颜色填充
import numpy as np
import matplotlib. pyplot as plt
theta= np. array( [ 0.25 , 0.45 , 0.65 , 0.75 , 1 , 1.35 , 1.65 , 2 , 0.25 ] )
r= [ 60 , 70 , 80 , 40 , 70 , 80 , 75 , 65 , 60 ]
plt. polar( theta* np. pi, r, 'ro-' , lw= 2 )
plt. fill( theta* np. pi, r, facecolor= 'y' )
plt. ylim( 0 , 100 )
plt. show( )
三维图
根据数据绘制三维曲线
import numpy as np
import matplotlib as mpl
import matplotlib. pyplot as plt
from mpl_toolkits. mplot3d import Axes3D
fig= plt. figure( )
ax= fig. gca( projection= '3d' )
theta= np. linspace( - 4 * np. pi, 4 * np. pi, 100 )
z= np. linspace( - 4 , 4 , 100 ) * 0.3
r= z** 4 + 1
x= r* np. sin( theta)
y= r* np. cos( theta)
ax. plot( x, y, z, 'b^-' , label= '3D Picture Test' )
mpl. rcParams[ 'legend.fontsize' ] = 10
ax. legend( )
plt. show( )
三维柱状图
import numpy as np
import mpl_toolkits. mplot3d
import matplotlib. pyplot as plt
x= np. random. randint( 0 , 40 , 10 )
y= np. random. randint( 0 , 40 , 10 )
z= 80 * abs ( np. sin( x+ y) )
ax= plt. subplot( projection= '3d' )
for xx, yy, zz in zip ( x, y, z) :
color= np. random. random( 3 )
ax. bar3d( xx, yy, 0 , dx= 1 , dy= 1 , dz= zz, color= color)
ax. set_xlabel( 'X' )
ax. set_xlabel( 'Y' )
ax. set_xlabel( 'Z' )
plt. show( )