Jae-Joon Lee wrote:
On Sat, Aug 1, 2009 at 5:04 PM, Andres Luhamaa<andres.luha...@ut.ee> wrote:
Thank You,

but now I have another little annoying issue. Besides clabel I add some
text manually to my plot with plt.text and sometimes the clabel and
plt.text overlap, and no matter in which order I plot them, the string
from clabel is always above the one from plt.text, but I would like, if
the manually added text would be more visible.


please define "more visible".
Maybe adjusting the zorder is sufficient?

http://matplotlib.sourceforge.net/api/artist_api.html?highlight=zorder#matplotlib.artist.Artist.set_zorder

If not, I would adjust the clable position manually (of course, this
is not a good choice if you need to do this for a lot of plots).
I'm not sure if there are more elegant solutions.

-JJ
Thank You once more, zorder is good but I also found the solution I was really looking for. Combination of get_window_extent and count_overlaps lets easily find overlapping text and just set clabels invisible. I add an example (modified from contour_demo.py) for future reference, if anyone is interested.

Best regards,
Andres

import matplotlib
import numpy as np
import matplotlib
matplotlib.use('Agg')
import matplotlib.cm as cm
import matplotlib.mlab as mlab
import matplotlib.pyplot as plt
matplotlib.rcParams['xtick.direction'] = 'out'
matplotlib.rcParams['ytick.direction'] = 'out'
delta = 0.025
x = np.arange(-3.0, 3.0, delta)
y = np.arange(-2.0, 2.0, delta)
X, Y = np.meshgrid(x, y)
Z1 = mlab.bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0)
Z2 = mlab.bivariate_normal(X, Y, 1.5, 0.5, 1, 1)
# difference of Gaussians
Z = 10.0 * (Z2 - Z1)
# Create a simple contour plot with labels using default colors.  The
# inline argument to clabel will control whether the labels are draw
# over the line segments of the contour, removing the lines beneath
# the label

# plot contours
CS = plt.contour(X, Y, Z)

# add many labels to make effect more clear
CL=plt.clabel(CS, inline=1, fontsize=10,colors='k')
CL1=plt.clabel(CS, inline=1, fontsize=10,colors='k')
CL2=plt.clabel(CS, inline=1, fontsize=10,colors='k')
CL3=plt.clabel(CS, inline=1, fontsize=10,colors='k')
CL4=plt.clabel(CS, inline=1, fontsize=10,colors='k')

## draw "important" text 
TTT=plt.text(0,0.7,'important',bbox=dict(fc='0.9', alpha=0.5))
TTT2=plt.text(0.3,0.4,'important2',bbox=dict(fc='0.9', alpha=0.5))
plt.draw()
TTT2we=TTT2.get_window_extent()
## Find out, if clabels and second text overlap
for i in CL,CL1,CL2,CL3,CL4:
    for j in i:
        kast=j.get_window_extent()
        if kast.count_overlaps([TTT2we,])>0:
            j.set_visible(False)
plt.savefig('contourtest',type='png')
------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to