gdm
2015-02-18 09:27:12 UTC
New matplotlib user here. Sometimes I like to make figures with multiple
axes, and have lines that cross multiple axes. I've run in to problems with
coordinates when doing this. One such problem is that axes.get_position()
seems to return incorrect coordinates for an axes with a fixed aspect ratio.
However, after calling pyplot.show() (or fig.savefig()), it returns the
correct coordinates.
Here is some example code:
#########################
import numpy
import matplotlib.pyplot as plt
# make up some data
x = numpy.arange(10)
y = numpy.sin(x)
y2 = numpy.cos(x)
# generate the figure
fig = plt.figure()
# setup the first axes
ax1 = fig.add_subplot(121)
plt.plot(x,y)
# setup the second axes with axis ratio
ax2 = fig.add_subplot(122, aspect=6)
plt.plot(x, y2)
# Print out the axes position after various operations
print "aaa", ax2.get_position()
plt.draw()
print "bbb", ax2.get_position()
fig.canvas.draw()
print "ccc", ax2.get_position()
plt.show(block=False)
print "yyy", ax2.get_position()
##########################
Running this code produces the following output:
aaa Bbox('array([[ 0.54772727, 0.1 ],\n [ 0.9 , 0.9
]])')
bbb Bbox('array([[ 0.54772727, 0.1 ],\n [ 0.9 , 0.9
]])')
ccc Bbox('array([[ 0.54772727, 0.1 ],\n [ 0.9 , 0.9
]])')
yyy Bbox('array([[ 0.54772727, 0.18686869],\n [ 0.9 ,
0.81313131]])')
P.S.: I think this might be related to an issue noted here:
http://stackoverflow.com/questions/11900654/get-position-does-strange-things-when-using-a-colorbar
--
View this message in context: http://matplotlib.1069221.n5.nabble.com/axes-get-position-inaccurate-until-after-savefig-tp44954.html
Sent from the matplotlib - users mailing list archive at Nabble.com.
axes, and have lines that cross multiple axes. I've run in to problems with
coordinates when doing this. One such problem is that axes.get_position()
seems to return incorrect coordinates for an axes with a fixed aspect ratio.
However, after calling pyplot.show() (or fig.savefig()), it returns the
correct coordinates.
Here is some example code:
#########################
import numpy
import matplotlib.pyplot as plt
# make up some data
x = numpy.arange(10)
y = numpy.sin(x)
y2 = numpy.cos(x)
# generate the figure
fig = plt.figure()
# setup the first axes
ax1 = fig.add_subplot(121)
plt.plot(x,y)
# setup the second axes with axis ratio
ax2 = fig.add_subplot(122, aspect=6)
plt.plot(x, y2)
# Print out the axes position after various operations
print "aaa", ax2.get_position()
plt.draw()
print "bbb", ax2.get_position()
fig.canvas.draw()
print "ccc", ax2.get_position()
plt.show(block=False)
print "yyy", ax2.get_position()
##########################
Running this code produces the following output:
aaa Bbox('array([[ 0.54772727, 0.1 ],\n [ 0.9 , 0.9
]])')
bbb Bbox('array([[ 0.54772727, 0.1 ],\n [ 0.9 , 0.9
]])')
ccc Bbox('array([[ 0.54772727, 0.1 ],\n [ 0.9 , 0.9
]])')
yyy Bbox('array([[ 0.54772727, 0.18686869],\n [ 0.9 ,
0.81313131]])')
P.S.: I think this might be related to an issue noted here:
http://stackoverflow.com/questions/11900654/get-position-does-strange-things-when-using-a-colorbar
--
View this message in context: http://matplotlib.1069221.n5.nabble.com/axes-get-position-inaccurate-until-after-savefig-tp44954.html
Sent from the matplotlib - users mailing list archive at Nabble.com.