调整动画Axes3D散点图(matplotlib)上的空白边距

时间:2017-06-02 01:11:51

标签: python animation matplotlib 3d

我正在使用matplotlib 1.2.1,现在仅限于该版本。我遇到的问题是轴标签的拥挤和框架底部的刻度与这个旋转的图。我已经尝试了plt.adjust_subplots,我尝试过tight_layout,更改了图形大小,ax.dist等等,但似乎没有任何改变外观,如下面的示例图所示。这只是一帧,但通常在绘图旋转时,它会在底部离开帧(特别是当刻度和标签更大时)。也许我的问题是我放置ax.dist参数的地方?

如何在此动画情节的底部添加更多空白?作为奖励,我怎样才能摆脱边缘处混乱的双网格线?谢谢。

enter image description here

import matplotlib as mpl
import matplotlib.pyplot as plt
plt.rcParams['animation.ffmpeg_path']='C:/FFMPEG/bin/ffmpeg.exe'
import matplotlib.animation as animation
from mpl_toolkits.mplot3d import Axes3D

def format_3d_ax(ax):
    ax.w_xaxis.set_pane_color((1.0,1.0,1.0,1.0))
    ax.w_yaxis.set_pane_color((1.0,1.0,1.0,1.0))
    ax.w_zaxis.set_pane_color((1.0,1.0,1.0,1.0))
    ax.w_xaxis._axinfo['grid'].update({'linewidth':0.25,'color':'black'})
    ax.w_yaxis._axinfo['grid'].update({'linewidth':0.25,'color':'black'})
    ax.w_zaxis._axinfo['grid'].update({'linewidth':0.25,'color':'black'})

def rotate(i,ax, angles, elev):
    ax.view_init(elev,angles[i])
    plt.draw()
    return ax

def rotate_3d(fig,ax,angles,elev):
    frames=len(angles)
    ani=animation.FuncAnimation(fig,rotate, fargs=(ax,angles, elev),blit=True,
                                 frames=frames, interval=200)
    return ani

fig=plt.figure(figsize=(12,7.6))
ax=Axes3D(fig)
ax.view_init(elev=25, azim=0)
format_3d_ax(ax)
ax.set_xlabel('Reasonably sized x label')
ax.set_ylabel('Reasonably sized y label')
ax.set_zlabel('z label')

ax.scatter([1],[1],[1], marker='.', s=80)

ani=rotate_3d(fig,ax,range(0,45),25)

Writer=animation.writers['ffmpeg']
writer=Writer(fps=30, bitrate=2000)
ani.save('C:/Temp/test.mp4', writer=writer, dpi=300)

print ('Done') #helps to know when the writer is done. 

0 个答案:

没有答案