我正在用一堆多边形绘制一个曲面。下面的绘图非常简单。在
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
我得到的图像如下。大的空白和微小的数字。我希望这个图形能覆盖大部分空间。 我怎么才能做到呢?在
修改空白的几种方法:
减少轴内的空白。为此,可以使用以下方法修改}限制:
x
、y
和{减少轴外的空白。为此,可以使用:
最后,您可以在调用
savefig
时保存一部分数据。您可以使用bbox_inches
kwarg修改此区域,方法是使用实际的Bbox
,而不是将其设置为tight
。例如,让我们考虑来自^{} gallery 的图像。请注意,我已经更改了轴和图形的背景颜色,因此它们在下面的页面上显示得很清楚。在
通过设置
fig.subplots_adjust(top=1, bottom=0, left=0, right=1)
,可以减少图形边距。这可能足够,也可能不够,这取决于实际数字。在还要注意,如果axes aspect设置为相等,
figsize
必须是平方的。(这里不是这种情况,但在其他情况下可能需要)。在最后一个要转动的旋钮是减小轴的限制。可以将这些值设置为较小的值,以减少对象周围的空白。 例如,在绘制一个半径为1的球体时,可能会试图将限制设置为
[-1,1]
,以使整个球体适合绘图。但是,这会留下很多空白。将限制减少到[-0.57,0.57]
将使球体很好地适应图形。为了看到这个效果,我在下面的例子中打开了轴。在相关问题 更多 >
编程相关推荐