John Hunter wrote:
> On Mon, Mar 15, 2010 at 3:16 PM, klukas <klu...@wisc.edu> wrote:
>   
>> It's my understanding that there is no built-in method for generating a
>> "broken axis" (where you skip over some range of values, indicating this
>> with some graphical mark).  I wanted to do this, so I've put together a
>> function which seems to be fairly robust, and I thought I might propose it
>> as a starting point if there's interest in having a built-in facility for
>> broken axes.
>>
>>     
> This is a nice start of an oft requested feature, and we are
> definitely interested.  It is enabled by the spine contribution of
> Andrew, so you can turn off the upper and lower spines between the
> break, so it is nice to see some unintended benefits of his
> refactoring.
>
>
> An alternative implementation could craft a custom transform using
> some custom artists for spines, but this might be a good bit harder.
> Do you have an opinion Andrew on this approach?
>   

John, I'm attaching a helper function I wrote to do just this.
Unfortunately, I don't have time to attempt to merge this into MPL right
now...

On Mon, Mar 15, 2010 at 3:16 PM, klukas <klu...@wisc.edu> wrote:

> The only real problems here is that you need to
> explicitly plot things on both the upper and lower axes, and then I haven't
> figured out how to push out the y-axis label of the main axes object so it
> doesn't overlap with the tick labels of the upper and lower axes.  So, I
> instead moved the y-labels of the upper and lower axes so that they appear
> at the center of the axis, but this is problematic.  Any thoughts on how to
> do that part better?

klukas, I'm afraid I don't understand your issue... Can you explain using it 
differently?

-Andrew

def add_spine_break(ax,spine_name,
                    data_loc, data_shift_amount=5, data_width=10,
                    axes_shift_amount = 0.05,
                    axis='y'):
    """draw a white parallelogram patch over the axis line at data_loc"""
    import matplotlib.path as mpath
    import matplotlib.patches as mpatches

    t = ax.spines[spine_name].get_transform()
    axes_coords = [-axes_shift_amount, axes_shift_amount,
                   axes_shift_amount,
                   -axes_shift_amount]
    data_coords = [ data_loc-data_shift_amount, data_loc+data_shift_amount,
                    data_loc+data_shift_amount+data_width,
                    data_loc-data_shift_amount+data_width ]

    if axis=='y':
        xs = axes_coords
        ys = data_coords
    elif axis=='x':
        xs = data_coords
        ys = axes_coords
    else:
        raise ValueError('unknown axis: %s'%axis)

    result = {}
    if 1: # white patch
        verts = []
        for xi,yi in zip(xs,ys):
            verts.append( (xi,yi) )
        verts.append( (0,0) )
        codes = [mpath.Path.MOVETO] + \
                [mpath.Path.LINETO]*(len(verts)-2) + \
                [mpath.Path.CLOSEPOLY]
        path = mpath.Path( verts, codes )
        patch = mpatches.PathPatch(path,edgecolor='none',facecolor='w')
        ax.add_artist(patch)

        patch.set_clip_on(False)
        patch.set_transform(t)
        patch.set_zorder(100)
        result['white_patch']=patch

    if 1: # black lines
        verts = []
        for xi,yi in zip(xs,ys):
            verts.append( (xi,yi) )
        codes = [mpath.Path.MOVETO] + \
                [mpath.Path.LINETO] + \
                [mpath.Path.MOVETO] + \
                [mpath.Path.LINETO]
        path = mpath.Path( verts, codes )
        patch = mpatches.PathPatch(path,edgecolor='k',facecolor='none')
        ax.add_artist(patch)

        patch.set_clip_on(False)
        patch.set_transform(t)
        patch.set_zorder(101)
        result['black_lines']=patch
------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel

Reply via email to