I tried to put some code to check overlapping texts.
The code runs, but I'm not sure if the code is correct. Texts still
overlap but I haven't checked if this is due to the incorrect code or
But I believe it gives you enough idea how to fix things.
You have several hundreds of candidate points for a few cases. No
doubt it takes so long.
On Mon, Mar 1, 2010 at 6:07 AM, Andrea Gavana <andrea.gavana@...> wrote:
> Hi Jae-Joon & All,
> On 28 February 2010 03:09, Jae-Joon Lee wrote:
>> If I read your correctly,
>> for l, b in zip(x, y):
>> # And here I work with data coordinates (!)
>> dashBox = Bbox.from_bounds(l, b, width+5, height+5)
>> badness = 0
>> for line in lines:
>> if line.intersects_bbox(dashBox):
>> badness += 1
>> x, y (therefore l, b) in data coordinate.
>> width, height?? this seems to be some wx specific coordinate, i have no idea.
>> lines (therefore line) in display coordinate.
>> converting x,y to display coordinate should straight forward. But I'm
>> not sure what kind of coordinate width and height has. Is it a method
>> of some class derived from matplotlib's Text?? If then, the extent of
>> the text can be measured using the get_window_extent method. This
>> requires a renderer instance, which should be known if the method is
>> called during the drawing time.
>> Again, post a complete but simple(!) code.
> OK, I think I got a complete code. Not super-simple, but simple enough
> I believe. After you run it you'll see a bunch of points and lines
> with some text. If you left-click inside the axis this will start the
> calculations for the "optimal positioning". There are a couple of
> 1) The code I have looks only for optimal positioning with respect to
> lines in the plot, it doesn't include texts (I don't know how to do
> it); You'll see what I mean if you run the code, the "optimally"
> positioned texts overlap with other text in the plot, and with
> themselves too (i.e., one "optimally" positioned text overlap with
> another "optimally" positioned text);
> 2) The code as it stands it's veeeeery slow. On my (relatively fast)
> computer, it takes almost 6 seconds to "optimally" position 14 labels.
> In order to run the code, you'll also need the "lines.txt" file, which
> contains the main lines coordinates. Sorry about this extra file but I
> wanted it to be as close as possible to my use-case.
> Thank you in advance for your suggestions.
> "Imagination Is The Only Weapon In The War Against Reality."