Dear All,
I am aware that this question has already been asked several times on the mailing list, see e.g.
However, in the following snippet, nothing I tried has been able to reduce the amount of white space around the figure (including toying around with
ax = plt.axes([0.0, 0.0, 1.0, 1.0])
)
Of course, one can always resort to pdfcrop, but I believe there must be a better solution to resize the margins from matplotlib.
Please see the snippet at the end of the email.
Every suggestion is welcome.
Cheers
Lorenzo
##############################################################################3
#!/usr/bin/env python
"""
See pcolor_demo2 for a much faster way of generating pcolor plots
"""
from __future__ import division
from pylab import *
from matplotlib import rc
def func3(x,y):
return (1- x/2 + x**5 + y**3)*exp(-x**2-y**2)
def func4(x,y):
theta=arcsin(y)
return cos(theta)
def func5(x,y):
return abs(sin(y))
def func6(x,y):
return abs(cos(y))
# make these smaller to increase the resolution
dx, dy = 0.0025, 0.0025
# x = arange(-1.0, 1.0, dx)
# y = arange(-1.0, 1.0, dy)
x = arange(-pi, pi, dx)
y = arange(-pi, pi, dy)
print("x is, " )
print (x)
X,Y = meshgrid(x, y)
Z = func6(X, Y)
# print "Z is, ", Z
ini=pi/2.+0.5
fig = plt.figure(figsize=(6,6))
ax = fig.add_subplot(111)
ax.axis('off')
figtext(.55, .8,r'${\bf J}^\perp$', fontdict=None,fontsize=30)
im = imshow(Z,cmap=cm.jet, extent=(-pi, pi, -pi, pi))
im.set_interpolation('bilinear')
im.set_clip_path(Circle((0,0),pi/2., transform=ax.transData))
# ax = plt.axes([0.0, 0.0, 1.0, 1.0]) # leaves no white space around the axes
annotate("", xy=(-pi/2., 0), xytext=(-ini, 0), arrowprops=dict(fc="g"))
annotate("", xy=(-pi/2., .2), xytext=(-ini, .2), arrowprops=dict(fc="g"))
annotate("", xy=(-pi/2., -.2), xytext=(-ini, -.2), arrowprops=dict(fc="g"))
annotate("", xy=(-pi/2., .4), xytext=(-ini, .4), arrowprops=dict(fc="g"))
annotate("", xy=(-pi/2., -.4), xytext=(-ini, -.4), arrowprops=dict(fc="g"))
annotate("", xy=(-pi/2., .6), xytext=(-ini, .6), arrowprops=dict(fc="g"))
annotate("", xy=(-pi/2., -.6), xytext=(-ini, -.6), arrowprops=dict(fc="g"))
annotate("", xy=(-pi/2., .8), xytext=(-ini, .8), arrowprops=dict(fc="g"))
annotate("", xy=(-pi/2., -.8), xytext=(-ini, -.8), arrowprops=dict(fc="g"))
annotate("", xy=(-pi/2., 1), xytext=(-ini, 1), arrowprops=dict(fc="g"))
annotate("", xy=(-pi/2., -1), xytext=(-ini, -1), arrowprops=dict(fc="g"))
annotate("", xy=(-pi/2., 1.2), xytext=(-ini, 1.2), arrowprops=dict(fc="g"))
annotate("", xy=(-pi/2., -1.2), xytext=(-ini, -1.2), arrowprops=dict(fc="g"))
annotate("", xy=(-pi/2., 1.4), xytext=(-ini, 1.4), arrowprops=dict(fc="g"))
annotate("", xy=(-pi/2., -1.4), xytext=(-ini, -1.4), arrowprops=dict(fc="g"))
annotate("", xy=(pi/2., 0), xytext=(ini, 0), arrowprops=dict(fc="g"))
annotate("", xy=(pi/2., .2), xytext=(ini, .2), arrowprops=dict(fc="g"))
annotate("", xy=(pi/2., -.2), xytext=(ini, -.2), arrowprops=dict(fc="g"))
annotate("", xy=(pi/2., .4), xytext=(ini, .4), arrowprops=dict(fc="g"))
annotate("", xy=(pi/2., -.4), xytext=(ini, -.4), arrowprops=dict(fc="g"))
annotate("", xy=(pi/2., .6), xytext=(ini, .6), arrowprops=dict(fc="g"))
annotate("", xy=(pi/2., -.6), xytext=(ini, -.6), arrowprops=dict(fc="g"))
annotate("", xy=(pi/2., .8), xytext=(ini, .8), arrowprops=dict(fc="g"))
annotate("", xy=(pi/2., -.8), xytext=(ini, -.8), arrowprops=dict(fc="g"))
annotate("", xy=(pi/2., 1), xytext=(ini, 1), arrowprops=dict(fc="g"))
annotate("", xy=(pi/2., -1), xytext=(ini, -1), arrowprops=dict(fc="g"))
annotate("", xy=(pi/2., 1.2), xytext=(ini, 1.2), arrowprops=dict(fc="g"))
annotate("", xy=(pi/2., -1.2), xytext=(ini, -1.2), arrowprops=dict(fc="g"))
annotate("", xy=(pi/2., 1.4), xytext=(ini, 1.4), arrowprops=dict(fc="g"))
annotate("", xy=(pi/2., -1.4), xytext=(ini, -1.4), arrowprops=dict(fc="g"))
# annotate("", xy=( -1.4, -pi/2), xytext=(-1.4,ini), arrowprops=dict(fc="g"))
annotate("", xy=(0., ini+1.), xytext=(0, -ini), arrowprops=dict(fc="black"))
ax.annotate('', xy=(-.3, 2.4), xycoords='data',
xytext=(-.4, 2.2), # textcoords='offset points',
arrowprops=dict(arrowstyle="->",
connectionstyle="angle3,angleA=0,angleB=-10"),
)
savefig("first-plot.pdf")
clf()