我正在用多邊形羣繪製曲面。繪圖非常簡單,如下所示。刪除Axes3d中的空白(matplotlib)
def plotSurface(cell, numOfLayer, name=None, alpha = 0.5):
#import the libraries
from mpl_toolkits.mplot3d import Axes3D
import matplotlib as mpl
from mpl_toolkits.mplot3d.art3d import Poly3DCollection
import numpy as np
import matplotlib.pyplot as plt
#limits of the plot
radius = (numOfLayer>1)*(np.sqrt(3.)*(numOfLayer-1)-Length)+Length#the radius of circle to be projected on
#plotting part
fig = plt.figure(frameon=False,figsize=(12,10))
ax = Axes3D(fig)
ax.set_xlim((-2*radius,2*radius))
ax.set_ylim((-2*radius,2*radius))
ax.set_zlim((-0.5*radius,2*radius))
ax.axis('off')
#fig = plt.figure()
#ax = fig.gca(projection='3d')
##iterating through the cell##
for stuff happening here : verts are the polygon vertices
#adding to 3d plot
ax.add_collection3d(Poly3DCollection(verts,alpha = alpha))
if name == None:#plot the figure
plt.show()
else:
plt.savefig(name,bbox_inches='tight')
return
我得到的圖像如下所示。與小圖的大白色空間。我想讓這個數字覆蓋大部分空間。 我該如何做到這一點?
減少軸限制?例如'ax.set_xlim(-1.1 *半徑,1.1 *半徑)'等。 – tom
沒有我使用的軸限制只適合繪製的形狀。所以這不是解決方案 –
'fig.subplots_adjust(left = 0,right = 1,bottom = 0,top = 1)'將移除軸外的很多空白 – tom