Reputation: 735
I'm trying to create an animation with two subplots--one 3D and another 2D. I can't seem to figure out if there is a way to get better font rendering from the 2D axes however. I tried playing around with various settings with font_manager, and even changing the frame_format to raw, but I've had no success. Does anyone have any ideas how to fix this? I get the same results with mpeg4.
The strange thing is that the 3D figure seems to render the font properly.
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
import matplotlib.animation as animation
from mpl_toolkits.mplot3d import Axes3D
w, h = matplotlib.figure.figaspect(.5)
fig = plt.figure(figsize=(w,h))
ax3d = fig.add_subplot(121, projection='3d')
ax2d = fig.add_subplot(122)
ax3d.set_xlim(-3, 3)
ax3d.set_ylim(-3, 3)
ax3d.azim = -90
ax3d.elev = 0
ax3d.set_title('Car on Parking Ramp')
ax2d.set_xlim(-20,20)
ax2d.set_ylim(-20,20)
ax2d.set_ylabel('y')
ax2d.set_xlabel('x')
ax2d.set_title('Intersection with z=0')
''' Helix '''
K = 3 ## Angular velocity
H = 2*np.pi ## Height
t = np.linspace(0, H, 100, endpoint=True)
x = np.cos(K*t)
y = np.sin(K*t)
z = H - t
ax3d.plot(x, y, z, color='k')
''' z = 0 Plane '''
xx, yy = np.meshgrid([-20,20], [-20,20])
ax3d.plot_surface(xx, yy, 0, alpha=0.3, facecolor='b', rstride=1, cstride=1, shade=True)
ax3d.set_axis_off()
''' Tangent Line Data '''
xdata = np.array([ np.cos(K*t), np.cos(K*t) - K*(H - t)*np.sin(K*t) ])
ydata = np.array([ np.sin(K*t), np.sin(K*t) + K*(H - t)*np.cos(K*t) ])
''' Graph Lines '''
proj, = ax2d.plot([],[])
tangent, = ax3d.plot([], [], [], color='b')
def update_graph(n, tangent, proj, xdata, ydata):
tangent.set_data(xdata[:,n],
ydata[:,n])
tangent.set_3d_properties([H - t[n], 0])
proj.set_xdata(xdata[1,:n])
proj.set_ydata(ydata[1,:n])
ani = animation.FuncAnimation(fig, update_graph, len(t),
fargs=(tangent, proj, xdata, ydata), interval=75, blit=True)
ani.save('im.gif', writer='imagemagick', fps=10)
#ani.save('im.mp4', extra_args=['-vcodec', 'libx264'])
Upvotes: 3
Views: 694
Reputation: 36
For people who face the same issue, it's indeed related to matplotlib backend.
Using different backend might help. In my case, the
%matplotlib nbagg
solved it (thanks to the linked question: Pixelated fonts when plot is saved as jpeg) .
Upvotes: 1