Let's say I am doing a 3D scatter plot with matplotlib. I am using the code given here: https://matplotlib.org/2.1.1/gallery/mplot3d/scatter3d.html
For my purposes I need to remove the axes, ticklevels etc. So I am doing this:
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.set_xticklabels([])
ax.set_yticklabels([])
ax.set_zticklabels([])
ax.set_axis_off()
I am also removed all the axis labels. To remove the white padding, I am saving the figure like this:
plt.savefig("test.png", bbox_inches = 'tight', pad_inches = 0)
plt.show()
But still there are white paddings, the generated figure looks like this:

But what I want is a figure that bounds only the portion of the figure where all the data points are, like this:



ax.set_xlimandax.set_ylimto limit your plot window to your liking - Arjunbbox_inches = 'tight'you will need to provide a custom bounding box, with the extent you desire. - ImportanceOfBeingErnestbbox_inches = matplotlib.transforms.Bbox.from_extents(1,1,5,3.8)? change the numbers to your liking. - ImportanceOfBeingErnest