fancy box around text

Hello,

The attached are a small subclass of matplotlib.text.Text I have
created which draws a (somewhat) fancy box around the text (see the
attached example ). This is similar to the current implementation of
bbox drawing in matpliotlib.text.Text class. A few differences are,

* how the rotation is handled. The box is also rotated
* optional shadow.

I also attach a small patch to text.py, which enables a use of a
custom bbox_artist.

A simple example,

    from textbox import Text, TextBoxArtist, RoundBox

    t = Text(0., 0., "test", size=20, rotation=30.,
                bbox = dict(artist=TextBoxArtist(RoundBox()))
                )
    gca().add_artist(t)

With the text.py patch, you may do

    from textbox import TextBoxArtist, RoundBox

    gca().text(0., 0., "test", size=20, rotation=30.,
                bbox = dict(artist=TextBoxArtist(RoundBox()))
                )

More examples are found in the example file attached. And with some
creativity, you can make your own fancy box.

It would be good if these can be included in the matplotlib. At least,
can the patch for the text.py be applied?
Regards,

-JJ

textbox.png

textbox.tgz (2.72 KB)

text_bbox_artist.diff (587 Bytes)

I am happy to include this functionality, but let's build it into the
standard bbox rather than introduce a new subclass. I see no reason
why they need to be separated.

JDH

···

On Thu, Sep 11, 2008 at 1:13 PM, Jae-Joon Lee <lee.j.joon@...149...> wrote:

It would be good if these can be included in the matplotlib. At least,
can the patch for the text.py be applied?

Thanks John,

I'm afraid that I'm not quite sure what you're suggesting, and will be
grateful if you describe it more specifically.

As of now, textbox.py has two classes (+Text class which is not needed
with text.py patch).

TextBoxBase and its derivatives : despite its name (which could be a
poor choice), the whole purpose of this class is to produce a Path
around any given square box (like bbox).

TextBoxArtist : The instance of this class a callable object which
creates a PathPatch object and draw it around the given Text instance.
This is to simulate the patches.bbox_artist() function.

So, could you elaborate how you want things arranged?

Regards,

-JJ

···

On Thu, Sep 11, 2008 at 4:07 PM, John Hunter <jdh2358@...149...> wrote:

On Thu, Sep 11, 2008 at 1:13 PM, Jae-Joon Lee <lee.j.joon@...149...> wrote:

It would be good if these can be included in the matplotlib. At least,
can the patch for the text.py be applied?

I am happy to include this functionality, but let's build it into the
standard bbox rather than introduce a new subclass. I see no reason
why they need to be separated.

JDH

Sorry Jae-Joon -- I was in a big hurry yesterday (in the financial
industry we're a bit busy these days) and I forgot that the
mind_reader module had not yet been committed to svn.

First, I'd like to say that these boxes look really nice, and I think
they enhance presentation charts in many contexts (eg business
presentations) so thanks a lot for contributing them.

I think the best organization is to put all of this functionality
(including the textbox code) into text.py and have the default text
instance support both the standard text box (Rectangle) and the
enhanced ones you have provided. So basically, just your text.py
patch and move all the support code into text.py. I'd also like to
put your example file in the pylab examples directory and add it to
examples/tests/backend_driver.py.

If you can do all that and submit it as a sf patch, that would be
great. Alternatively, if you would like to send me your sf id, I can
add you as a developer and you can contribute it directly.

Thanks again,
JDH

JDH

···

On Thu, Sep 11, 2008 at 4:19 PM, Jae-Joon Lee <lee.j.joon@...149...> wrote:

Thanks John,

I'm afraid that I'm not quite sure what you're suggesting, and will be
grateful if you describe it more specifically.

Thanks John,

I think I'd better use a sf patch initially so that you or others can
review and improve it. I'll definitely need some help with
documentation as my English can be horrible sometime. On the other
hand, it would be much easier for me to do some maintenance work if I
can commit the changes directly. So, my sf id is "leejjoon" and it
will be great if you add me as a developer.

I guess this fancy box thing can be used with other artist objects
also, although the legend object is an only object I can think of now.
And my personal inclination is put those support code into patches.py
and have a patch class around it, i.e., a FancyBoxPatch class which is
initialized with bbox-like object and draw a fancy box around the
given bbox. And let the Text and the Legend class use this
FancyBoxPatch. In the current matplotlib, both the Text and the Legend
class uses the Patch class for drawing a bbox. So how do you think?

What I also want to see in matplotlib is a fancy annotation. I have
some working code (although I'm planning some major code
reorganization) and willing to contribute it if there is an interest
(see the attached example). As you can easily guess, the fancy
annotation share some of its core with the fancy box. So if you're
also willing to include the fancy annotation things in matplotlib,
I'll put some more effort in the code reorganization so that it can
nicely fit in the current matplotlib classes.

Regards,

-JJ

ps. I just wanted to mention that implementing these fancy boxes
became possible with the bezier path support in matplotlib. So my
thanks to Michael.

test_fancy_annotation.jpg

···

On Fri, Sep 12, 2008 at 11:45 AM, John Hunter <jdh2358@...149...> wrote:

On Thu, Sep 11, 2008 at 4:19 PM, Jae-Joon Lee <lee.j.joon@...149...> wrote:

Thanks John,

I'm afraid that I'm not quite sure what you're suggesting, and will be
grateful if you describe it more specifically.

Sorry Jae-Joon -- I was in a big hurry yesterday (in the financial
industry we're a bit busy these days) and I forgot that the
mind_reader module had not yet been committed to svn.

First, I'd like to say that these boxes look really nice, and I think
they enhance presentation charts in many contexts (eg business
presentations) so thanks a lot for contributing them.

I think the best organization is to put all of this functionality
(including the textbox code) into text.py and have the default text
instance support both the standard text box (Rectangle) and the
enhanced ones you have provided. So basically, just your text.py
patch and move all the support code into text.py. I'd also like to
put your example file in the pylab examples directory and add it to
examples/tests/backend_driver.py.

If you can do all that and submit it as a sf patch, that would be
great. Alternatively, if you would like to send me your sf id, I can
add you as a developer and you can contribute it directly.

Thanks again,
JDH

JDH

Jae-Joon Lee wrote:

I guess this fancy box thing can be used with other artist objects
also, although the legend object is an only object I can think of now.
And my personal inclination is put those support code into patches.py
and have a patch class around it, i.e., a FancyBoxPatch class which is
initialized with bbox-like object and draw a fancy box around the
given bbox. And let the Text and the Legend class use this
FancyBoxPatch. In the current matplotlib, both the Text and the Legend
class uses the Patch class for drawing a bbox. So how do you think?
  

I like this suggestion. I can see this being generally useful.

What I also want to see in matplotlib is a fancy annotation. I have
some working code (although I'm planning some major code
reorganization) and willing to contribute it if there is an interest
(see the attached example). As you can easily guess, the fancy
annotation share some of its core with the fancy box. So if you're
also willing to include the fancy annotation things in matplotlib,
I'll put some more effort in the code reorganization so that it can
nicely fit in the current matplotlib classes.
  

Looking forward to it.

ps. I just wanted to mention that implementing these fancy boxes
became possible with the bezier path support in matplotlib. So my
thanks to Michael.
  

You're welcome. It's nice to see others picking this stuff up and running with it.

Cheers,
Mike

···

On Fri, Sep 12, 2008 at 11:45 AM, John Hunter <jdh2358@...149...> wrote:
  

On Thu, Sep 11, 2008 at 4:19 PM, Jae-Joon Lee <lee.j.joon@...149...> wrote:
    

Thanks John,

I'm afraid that I'm not quite sure what you're suggesting, and will be
grateful if you describe it more specifically.
      

Sorry Jae-Joon -- I was in a big hurry yesterday (in the financial
industry we're a bit busy these days) and I forgot that the
mind_reader module had not yet been committed to svn.

First, I'd like to say that these boxes look really nice, and I think
they enhance presentation charts in many contexts (eg business
presentations) so thanks a lot for contributing them.

I think the best organization is to put all of this functionality
(including the textbox code) into text.py and have the default text
instance support both the standard text box (Rectangle) and the
enhanced ones you have provided. So basically, just your text.py
patch and move all the support code into text.py. I'd also like to
put your example file in the pylab examples directory and add it to
examples/tests/backend_driver.py.

If you can do all that and submit it as a sf patch, that would be
great. Alternatively, if you would like to send me your sf id, I can
add you as a developer and you can contribute it directly.

Thanks again,
JDH

JDH

------------------------------------------------------------------------

------------------------------------------------------------------------

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
------------------------------------------------------------------------

_______________________________________________
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel
    
--
Michael Droettboom
Science Software Branch
Operations and Engineering Division
Space Telescope Science Institute
Operated by AURA for NASA

Thanks John,

I think I'd better use a sf patch initially so that you or others can
review and improve it. I'll definitely need some help with
documentation as my English can be horrible sometime. On the other
hand, it would be much easier for me to do some maintenance work if I
can commit the changes directly. So, my sf id is "leejjoon" and it
will be great if you add me as a developer.

OK, I added you as a developer, but you continue posting your patches
here and we will be happy to review and comment on them as we have
time.

I guess this fancy box thing can be used with other artist objects
also, although the legend object is an only object I can think of now.
And my personal inclination is put those support code into patches.py
and have a patch class around it, i.e., a FancyBoxPatch class which is
initialized with bbox-like object and draw a fancy box around the
given bbox. And let the Text and the Legend class use this
FancyBoxPatch. In the current matplotlib, both the Text and the Legend
class uses the Patch class for drawing a bbox. So how do you think?

Yes, if you can generalize it to a Patch instance this will be more
useful and then matplotlib.patches will be the place for it.
I notice that your current TextBoxArtist does not actually derive from
matplotlib.artist.Artist. If you intend it to be an Artist, you
should explictly inherit and implement draw and other required methods
(eg get_children if your Artist contains other artists)

What I also want to see in matplotlib is a fancy annotation. I have
some working code (although I'm planning some major code
reorganization) and willing to contribute it if there is an interest
(see the attached example). As you can easily guess, the fancy
annotation share some of its core with the fancy box. So if you're
also willing to include the fancy annotation things in matplotlib,
I'll put some more effort in the code reorganization so that it can
nicely fit in the current matplotlib classes.

These examples look very nice too! Send in a patch when you have
everything organized.

JDH

···

On Fri, Sep 12, 2008 at 2:46 PM, Jae-Joon Lee <lee.j.joon@...149...> wrote:

Hi,

I uploaded my patch.

https://sourceforge.net/tracker/index.php?func=detail&aid=2116614&group_id=80706&atid=560722

I added a FancyBboxPatch class in the patches.py. And changed
text.Text class to support it. Two examples are attached with this
email. I hope I have put enough documentation, but if anything is not
clear, just let me know. Also see if the current interfaces are
acceptable.

I only have placed two kind of boxstyles. I'll add more eventually.

Regards,

-JJ

fancybox_demo.py (4.51 KB)

fancytextbox_demo.py (538 Bytes)

···

On Fri, Sep 12, 2008 at 5:21 PM, John Hunter <jdh2358@...149...> wrote:

On Fri, Sep 12, 2008 at 2:46 PM, Jae-Joon Lee <lee.j.joon@...149...> wrote:

Thanks John,

I think I'd better use a sf patch initially so that you or others can
review and improve it. I'll definitely need some help with
documentation as my English can be horrible sometime. On the other
hand, it would be much easier for me to do some maintenance work if I
can commit the changes directly. So, my sf id is "leejjoon" and it
will be great if you add me as a developer.

OK, I added you as a developer, but you continue posting your patches
here and we will be happy to review and comment on them as we have
time.

I guess this fancy box thing can be used with other artist objects
also, although the legend object is an only object I can think of now.
And my personal inclination is put those support code into patches.py
and have a patch class around it, i.e., a FancyBoxPatch class which is
initialized with bbox-like object and draw a fancy box around the
given bbox. And let the Text and the Legend class use this
FancyBoxPatch. In the current matplotlib, both the Text and the Legend
class uses the Patch class for drawing a bbox. So how do you think?

Yes, if you can generalize it to a Patch instance this will be more
useful and then matplotlib.patches will be the place for it.
I notice that your current TextBoxArtist does not actually derive from
matplotlib.artist.Artist. If you intend it to be an Artist, you
should explictly inherit and implement draw and other required methods
(eg get_children if your Artist contains other artists)

What I also want to see in matplotlib is a fancy annotation. I have
some working code (although I'm planning some major code
reorganization) and willing to contribute it if there is an interest
(see the attached example). As you can easily guess, the fancy
annotation share some of its core with the fancy box. So if you're
also willing to include the fancy annotation things in matplotlib,
I'll put some more effort in the code reorganization so that it can
nicely fit in the current matplotlib classes.

These examples look very nice too! Send in a patch when you have
everything organized.

JDH

Hi Jae Joon -- thanks for uploading this. I have read through it once
and it looks pretty good -- thanks for doing the extra work to
properly document the kwargs using the auto-property infrastructure.

One request: could you submit the entire patch including the examples
as a single 'svn diff'? Then I can more easily apply it and test it.

Thanks,
JDH

···

On Wed, Sep 17, 2008 at 1:30 PM, Jae-Joon Lee <lee.j.joon@...149...> wrote:

Hi,

I uploaded my patch.

https://sourceforge.net/tracker/index.php?func=detail&aid=2116614&group_id=80706&atid=560722

Thanks John,

I made a single diff file and uploaded it.

https://sourceforge.net/tracker/index.php?func=detail&aid=2116614&group_id=80706&atid=560722

Regards,

-JJ

···

On Wed, Sep 17, 2008 at 3:01 PM, John Hunter <jdh2358@...149...> wrote:

On Wed, Sep 17, 2008 at 1:30 PM, Jae-Joon Lee <lee.j.joon@...149...> wrote:

Hi,

I uploaded my patch.

https://sourceforge.net/tracker/index.php?func=detail&aid=2116614&group_id=80706&atid=560722

Hi Jae Joon -- thanks for uploading this. I have read through it once
and it looks pretty good -- thanks for doing the extra work to
properly document the kwargs using the auto-property infrastructure.

One request: could you submit the entire patch including the examples
as a single 'svn diff'? Then I can more easily apply it and test it.

Thanks,
JDH

One thing I forgot to mention is that, in the Text class, draw()
method calls _draw_bbox() method. If I call the _draw_bbox() methods
after gc in draw() is created, then _draw_bbox call somehow changes
the gc in the original draw() method, which I think is not supposed to
happen. I haven't looked at this carefully, but this might only happen
in some specific backends (I'm using GtkCairo). Anyhow, as a
workaround, in the draw() method, _draw_bbox() is called before the gc
is created.

···

On Wed, Sep 17, 2008 at 3:49 PM, Jae-Joon Lee <lee.j.joon@...149...> wrote:

Thanks John,

I made a single diff file and uploaded it.

https://sourceforge.net/tracker/index.php?func=detail&aid=2116614&group_id=80706&atid=560722

Regards,

-JJ

On Wed, Sep 17, 2008 at 3:01 PM, John Hunter <jdh2358@...149...> wrote:

On Wed, Sep 17, 2008 at 1:30 PM, Jae-Joon Lee <lee.j.joon@...149...> wrote:

Hi,

I uploaded my patch.

https://sourceforge.net/tracker/index.php?func=detail&aid=2116614&group_id=80706&atid=560722

Hi Jae Joon -- thanks for uploading this. I have read through it once
and it looks pretty good -- thanks for doing the extra work to
properly document the kwargs using the auto-property infrastructure.

One request: could you submit the entire patch including the examples
as a single 'svn diff'? Then I can more easily apply it and test it.

Thanks,
JDH

s

One thing I forgot to mention is that, in the Text class, draw()
method calls _draw_bbox() method. If I call the _draw_bbox() methods
after gc in draw() is created, then _draw_bbox call somehow changes
the gc in the original draw() method, which I think is not supposed to
happen. I haven't looked at this carefully, but this might only happen
in some specific backends (I'm using GtkCairo). Anyhow, as a
workaround, in the draw() method, _draw_bbox() is called before the gc
is created.

I am not sure why the gc is being modified, but an alternative is to
get a new gc and then copy the properties

  newgc = renderer.new_gc()
  newgc.copy_properties(oldgc)

This might be a less brittle solution since in the distant future we
may not remember why the drawing order had t be the way it is.

JDH
JDH

···

On Wed, Sep 17, 2008 at 2:50 PM, Jae-Joon Lee <lee.j.joon@...149...> wrote:

OK, I've applied it. I reformatted some of the docstrings and
incorporated a bunch of the comments into the docstrings because they
will probably be helpful there to users reading the docs to figure out
what is going on. Let me know if this creates any problems, and
thanks again for the very nice patch and examples.

JDH

···

On Wed, Sep 17, 2008 at 2:49 PM, Jae-Joon Lee <lee.j.joon@...149...> wrote:

I uploaded my patch.

https://sourceforge.net/tracker/index.php?func=detail&aid=2116614&group_id=80706&atid=560722

Thanks John,
Everything seems fine.
Thanks again,

-JJ

···

On Wed, Sep 17, 2008 at 4:53 PM, John Hunter <jdh2358@...149...> wrote:

On Wed, Sep 17, 2008 at 2:49 PM, Jae-Joon Lee <lee.j.joon@...149...> wrote:

I uploaded my patch.

https://sourceforge.net/tracker/index.php?func=detail&aid=2116614&group_id=80706&atid=560722

OK, I've applied it. I reformatted some of the docstrings and
incorporated a bunch of the comments into the docstrings because they
will probably be helpful there to users reading the docs to figure out
what is going on. Let me know if this creates any problems, and
thanks again for the very nice patch and examples.

JDH