Issue
I created a surface plot of a gaussian using matplotlib:
num_pts = 1000
σ = 1.5
x = np.linspace(-5, 5, num_pts)
kernel1d = np.exp(-np.square(x) / (2 * σ * σ))
kernel2d = np.outer(kernel1d, kernel1d)
X, Y = np.meshgrid(x, x)
fig, ax = plt.subplots(figsize=(6,6), subplot_kw={"projection":"3d"})
ax.plot_surface(X, Y, kernel2d, cmap="viridis", linewidth=0, antialiased=True)
ax.set(xticks=[], yticks=[], zticks=[])
ax.grid(False)
ax.axis('off')
fig.savefig("test.svg", format="svg", transparent=True)
The output has a lot of dead space around the actual plot.
I tried layout=tight
which did not have any effect.
How can I maximize the size of the surface withing the figure assuming no need for any axis: ticks, labels, grid, etc...
Solution
You can play around with the pad_inches
value:
fig.savefig("test.svg", format="svg", transparent=True, bbox_inches='tight', pad_inches=-0.4)
Otherwise, perhaps you can try getting the bounding box containing the paths, and set the axes limits based on that: https://stackoverflow.com/a/76076555/7750891
Answered By - Anonymous
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.