Re: [Matplotlib-users] How to determine position of axes after imshow?

2012-08-07 Thread Mark Bakker
I tried a few things and found out that doing a pause works.
So why does a pause work, but a draw() or show() does not?
This all on Windows using the standard PythonXY installation.
Here is the code that works (testimage.py):

from pylab import *
c = ones((10,20))
ax = imshow(c)
pause(0.01)
print ax.get_axes().get_position()

Running from IPython:
run testimage
Bbox(array([[ 0.125 ,  0.2417],
   [ 0.9   ,  0.7583]]))


On Wed, Aug 1, 2012 at 8:56 PM, Stan West  wrote:

> **
>
> *From:* Mark Bakker [mailto:mark...@gmail.com]
> *Sent:* Monday, July 30, 2012 05:54
>
> Hello List,
>
> I am trying to determine the position of the axes after an imshow and am
> having problems.
> I get a different answer on my Mac (the correct answer) than Windows (the
> wrong answer).
>
> [...]
>
> Any thoughts? When I type the commands in at the IPython prompt it works
> most of the time (on Windows), but it never works when running the file.
> What in the world could be different?
>
> mp version 1.1.0 on both systems.
>
>  Are you using the same backend on both systems?
>
> Perhaps when you run the script within IPython on your Windows system, the
> show() call is not triggering a draw. You can force drawing by calling
> draw() before show(). I hope that helps.
>
--
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] zoomed_inset_axes bbox_to_anchor not working

2012-08-07 Thread darkside
Hi everyone,

I'm trying to make a zoom of a single plot. The problem is that the zoomed
axes yticks overlap with the yaxes so I tried to use the bbox_to_anchor
option in the zoom:
axins = zoomed_inset_axes(ax,
3,bbox_to_anchor=(0.4,0.4),bbox_transform=ax.transAxes, loc=2)

with different (x,y) parameters, but it's not working.

I also tried to move the figure by hand:
box = axins.get_position()
print box
axins.set_position([box.x0+0.5, box.y0,box.width, box.height])
box = axins.get_position()
print box

and I see that box numbers changing, but not in the plot.

Can anyone guess what I am doing wrong?

Thank you all!

PS: The full code for this plot is:

def plotvsdata(data,z,dl,nu):
"""
Plot of z vs. Dl for different nu values
"""

fig = p.figure(figsize=(12,8))
ax = p.subplot(111)

# FLRW light distance
ax.plot(z[0],Dl_lflrw(z[0],0.3,0.7),'k--',label=r'Dl $\Lambda$FLRW')
# mean data values
ax.plot(data.redshift,data.distance,'r.',label='SCP data')

p.xlabel('z',fontsize=18)
p.ylabel('Luminosity distance',fontsize=18)
p.grid(True)

#axins = zoomed_inset_axes(ax,3,loc=2,bbox_to_anchor=(0.5,0.5))
#axins = zoomed_inset_axes(ax,3,loc=2,bbox_to_anchor=(0.4,0.4)
,bbox_transform=ax.transAxes)
axins = zoomed_inset_axes(ax,
3,bbox_to_anchor=(1,1),bbox_transform=ax.transAxes, loc=2)
#box = axins.get_position()
#print box
#axins.set_position([box.x0+0.5, box.y0,box.width, box.height])
#box = axins.get_position()
#print box


# Kantowski equation
for i in range(len(z)):
ax.plot(z[i],dl[i],label=r'$\nu={0:1.2f}$'.format(nu[i]))
axins.plot(z[i],dl[i])
axins.plot(data.redshift,data.distance,'r.', label='SCP data')


#box = ax.get_position()
#ax.set_position([box.x0,box.y0,box.width*0.8,box.height])

ax.legend(loc=2,bbox_to_anchor=(1,1))


x,y = (0.86,1.3)
x2,y2 = (1,1.7)
axins.set_xlim(x,x2)
axins.set_ylim(y,y2)
axins.tick_params(axis='both',labelsize=12)
axins.xaxis.set_major_locator(MaxNLocator(2))
axins.yaxis.set_major_locator(MaxNLocator(3))
#box = axins.get_position()
#print box
#axins.set_position([box.x0+0.5, box.y0,box.width, box.height])
#box = axins.get_position()
#print box

# draw a bbox of the region to zoom and connecting lines between it
# and the zoomed box.
mark_inset(ax,axins,loc1=1,loc2=3, fc="none", ec="0.5")
#p.xticks(visible=False)
#p.yticks(visible=False)

p.draw()
p.show()
--
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] How to determine whether a window is closed?

2012-08-07 Thread Qian Peng
Hi,
In matplotlib, is there a way to check whether a window related to a
figure has been closed by user?

x=[1,2,3]
fig = plt.figure()
fig.show()
plt.plot(x,x)
plt.draw()

later in the code, I want to make draw some other line, possibly on the
same figure. I can switch to the preivious figure by

plt.figure(fig.number)

but it seems that even if fig has been closed by the user, this will still
work because the information stored in fig is still accessible. Then, this
fig.number would actually point some other picture.

So, is there any state information in fig that would tell whether the
window of fig has been closed by user?


Thanks

Qian
--
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users