import numpy as np
import matplotlib.pyplot as plt
x=np.array([10,20,30,40])
plt.pie(x)
plt.show()
import matplotlib.pyplot as plt
import numpy as np
from mpl_toolkits.mplot3d import Axes3D
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
# Cylinder
x=np.linspace(-1, 1, 100)
z=np.linspace(-2, 2, 100)
Xc, Zc=np.meshgrid(x, z)
Yc = np.sqrt(1-Xc**2)
# Draw parameters
rstride = 20
cstride = 10
ax.plot_surface(Xc, Yc, Zc, alpha=0.2, rstride=rstride, cstride=cstride)
ax.plot_surface(Xc, -Yc, Zc, alpha=0.2, rstride=rstride, cstride=cstride)
ax.set_xlabel("X")
ax.set_ylabel("Y")
ax.set_zlabel("Z")
plt.show()
是要这样的效果吗?
import numpy as np
import wxgl
import wxgl.glplot as glt
data = np.array([10,20,30,40])
color = ['#1f77b4', '#ff7f0e', '#2ca02c', '#d62728']
pieces = data/data.sum() * 360
start, end = 0, 0
for p, c in zip(pieces, color):
end += p
glt.circle((0,1,0), 0.8, color=c, arc=(start,end), cell=1, light=wxgl.BaseLight())
glt.circle((0,-1,0), 0.8, color=c, arc=(start,end), cell=1, light=wxgl.BaseLight())
glt.cylinder((0,1,0), (0,-1,0), 0.8, color=c, arc=(start,end), cell=1)
start = end
glt.show()