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




On Fri, Sep 12, 2008 at 5:21 PM, John Hunter <[EMAIL PROTECTED]> wrote:
> On Fri, Sep 12, 2008 at 2:46 PM, Jae-Joon Lee <[EMAIL PROTECTED]> 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
>
import matplotlib.pyplot as plt
import matplotlib.transforms as mtransforms
from matplotlib.patches import FancyBboxPatch


# Bbox object around which the fancy box will be drawn.
bb = mtransforms.Bbox([[0.3, 0.4], [0.7, 0.6]])

def draw_bbox(ax, bb):
    # boxstyle=square with pad=0, i.e. bbox itself.
    p_bbox = FancyBboxPatch((bb.xmin, bb.ymin),
                            abs(bb.width), abs(bb.height), 
                            boxstyle="square,pad=0.",
                            ec="k", fc="none", zorder=10.,
                            )
    ax.add_patch(p_bbox)

def test1(ax):

    # a fancy box with round corners. pad=0.1
    p_fancy = FancyBboxPatch((bb.xmin, bb.ymin),
                             abs(bb.width), abs(bb.height),
                             boxstyle="round,pad=0.1",
                             fc=(1., .8, 1.),
                             ec=(1., 0.5, 1.))


    ax.add_patch(p_fancy)

    ax.text(0.1, 0.8,
            r' boxstyle="round,pad=0.1"',
            size=10, transform=ax.transAxes)

    # draws control points for the fancy box.
    #l = p_fancy.get_path().vertices
    #ax.plot(l[:,0], l[:,1], ".")

    # draw the original bbox in black
    draw_bbox(ax, bb)


def test2(ax):

    # bbox=round has two optional argument. pad and rounding_size.
    # They can be set during the initiallization.
    p_fancy = FancyBboxPatch((bb.xmin, bb.ymin),
                             abs(bb.width), abs(bb.height),
                             boxstyle="round,pad=0.1",
                             fc=(1., .8, 1.),
                             ec=(1., 0.5, 1.))


    ax.add_patch(p_fancy)

    # boxstyle and its argument can be later modified with
    # set_boxstyle method. Note that the old attributes are simply
    # forgotten even if the boxstyle name is same.

    p_fancy.set_boxstyle("round,pad=0.1, rounding_size=0.2")
    #or
    #p_fancy.set_boxstyle("round", pad=0.1, rounding_size=0.2)

    ax.text(0.1, 0.8,
            ' boxstyle="round,pad=0.1\n rounding\\_size=0.2"',
            size=10, transform=ax.transAxes)

    # draws control points for the fancy box.
    #l = p_fancy.get_path().vertices
    #ax.plot(l[:,0], l[:,1], ".")
    
    draw_bbox(ax, bb)



def test3(ax):

    # mutation_scale determine overall scale of the mutation,
    # i.e. both pad and rounding_size is scaled according to this
    # value.
    p_fancy = FancyBboxPatch((bb.xmin, bb.ymin),
                             abs(bb.width), abs(bb.height),
                             boxstyle="round,pad=0.1",
                             mutation_scale=2.,
                             fc=(1., .8, 1.),
                             ec=(1., 0.5, 1.))


    ax.add_patch(p_fancy)

    ax.text(0.1, 0.8,
            ' boxstyle="round,pad=0.1"\n mutation\\_scale=2',
            size=10, transform=ax.transAxes)

    # draws control points for the fancy box.
    #l = p_fancy.get_path().vertices
    #ax.plot(l[:,0], l[:,1], ".")
    
    draw_bbox(ax, bb)



def test4(ax):

    # When the aspect ratio of the axes is not 1, the fancy box may
    # not be what you expected (green)
    
    p_fancy = FancyBboxPatch((bb.xmin, bb.ymin),
                             abs(bb.width), abs(bb.height),
                             boxstyle="round,pad=0.2",
                             fc="none",
                             ec=(0., .5, 0.), zorder=4)


    ax.add_patch(p_fancy)


    # You can compensate this by setting the mutation_aspect (pink).
    p_fancy = FancyBboxPatch((bb.xmin, bb.ymin),
                             abs(bb.width), abs(bb.height),
                             boxstyle="round,pad=0.3",
                             mutation_aspect=.5, 
                             fc=(1., 0.8, 1.),
                             ec=(1., 0.5, 1.))


    ax.add_patch(p_fancy)

    ax.text(0.1, 0.8,
            ' boxstyle="round,pad=0.3"\n mutation\\_aspect=.5',
            size=10, transform=ax.transAxes)
    
    draw_bbox(ax, bb)



def test_all():
    plt.clf()

    ax = plt.subplot(2, 2, 1)
    test1(ax)
    ax.set_xlim(0., 1.)
    ax.set_ylim(0., 1.)
    ax.set_title("test1")
    ax.set_aspect(1.)


    ax = plt.subplot(2, 2, 2)
    ax.set_title("test2")
    test2(ax)
    ax.set_xlim(0., 1.)
    ax.set_ylim(0., 1.)
    ax.set_aspect(1.)

    ax = plt.subplot(2, 2, 3)
    ax.set_title("test3")
    test3(ax)
    ax.set_xlim(0., 1.)
    ax.set_ylim(0., 1.)
    ax.set_aspect(1)

    ax = plt.subplot(2, 2, 4)
    ax.set_title("test4")
    test4(ax)
    ax.set_xlim(-0.5, 1.5)
    ax.set_ylim(0., 1.)
    ax.set_aspect(2.)

    plt.draw()
    plt.show()

test_all()
import matplotlib.pyplot as plt

plt.text(0.6, 0.5, "test", size=50, rotation=30.,
         ha="center", va="center", 
         bbox = dict(boxstyle="round",
                     ec=(1., 0.5, 0.5),
                     fc=(1., 0.8, 0.8),
                     )
         )

plt.text(0.5, 0.4, "test", size=50, rotation=-30.,
         ha="right", va="top", 
         bbox = dict(boxstyle="square",
                     ec=(1., 0.5, 0.5),
                     fc=(1., 0.8, 0.8),
                     )
         )

    
plt.draw()
plt.show()
-------------------------------------------------------------------------
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

Reply via email to