Since you call twinx then twiny, you're creating two additional axes, not one.
And I guess this is why labels are drawn twice. You may do

def twin(ax):
        ax2 = ax.figure.add_axes(ax.get_position(True),
                                   frameon=False)
        ax2.yaxis.tick_right()
        ax2.yaxis.set_label_position('right')
        ax.yaxis.tick_left()

        ax2.xaxis.tick_top()
        ax2.xaxis.set_label_position('top')
        ax.xaxis.tick_bottom()

        return ax2

ax = gca()
ax2 = twin(ax)
ax.scatter([0.4],[0.6])
ax2.scatter([10.],[10.])

draw()


Note that you need to manually adjust the view limits of each axes. If
you use sharex or sharey parameters for the axes, you can share their
view limits (this is how axes is created when twinx and twiny is
called). But then you cannot have different tick locators.

In case you need an axes with a same viewlimit as the original one but
just want to place ticks at different position, you may check my
related post.

http://sourceforge.net/mailarchive/forum.php?thread_name=4985DED6.90108%40head.cfa.harvard.edu&forum_name=matplotlib-users

-JJ


On Sun, Feb 8, 2009 at 5:07 PM, Thomas Robitaille
<thomas.robitai...@gmail.com> wrote:
> Hi everyone,
>
> I am plotting a figure where I need two independent x axes and two
> independent y axes. I've tried to use both twinx and twiny at the
> same time, and this works to some extent, but it looks like it is
> plotting the labels for the bottom x axis and the right-hand y axis
> twice, which makes me think that I must be doing something wrong (the
> numbers appear more 'bold'). The code is below. Is there a better way
> to do this?
>
> In reality, I don't need a different scale for the opposite axes, but
> I want to specify different Locator functions, but I assume that
> creating a new axes instance as done below is the only way to do this?
>
> Thanks for any advice,
>
> Thomas
>
> ###
> fig = figure()
> ax  = fig.add_subplot(111)
> ax2 = ax.twinx().twiny()
> for tick in ax.yaxis.get_major_ticks():
>        tick.label1On = True
>        tick.label2On = False
>        tick.tick1On = True
>        tick.tick2On = False
> for tick in ax.xaxis.get_major_ticks():
>        tick.label1On = True
>        tick.label2On = False
>        tick.tick1On = True
>        tick.tick2On = False
> for tick in ax2.yaxis.get_major_ticks():
>        tick.label1On = False
>        tick.label2On = True
>        tick.tick1On = False
>        tick.tick2On = True
> for tick in ax2.xaxis.get_major_ticks():
>        tick.label1On = False
>        tick.label2On = True
>        tick.tick1On = False
>        tick.tick2On = True
> ax.scatter([0.4],[0.6])
> ax2.scatter([10.],[10.])
> draw()
> ###
>
>
> ------------------------------------------------------------------------------
> Create and Deploy Rich Internet Apps outside the browser with Adobe(R)AIR(TM)
> software. With Adobe AIR, Ajax developers can use existing skills and code to
> build responsive, highly engaging applications that combine the power of local
> resources and data with the reach of the web. Download the Adobe AIR SDK and
> Ajax docs to start building applications today-http://p.sf.net/sfu/adobe-com
> _______________________________________________
> Matplotlib-users mailing list
> Matplotlib-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>

------------------------------------------------------------------------------
Create and Deploy Rich Internet Apps outside the browser with Adobe(R)AIR(TM)
software. With Adobe AIR, Ajax developers can use existing skills and code to
build responsive, highly engaging applications that combine the power of local
resources and data with the reach of the web. Download the Adobe AIR SDK and
Ajax docs to start building applications today-http://p.sf.net/sfu/adobe-com
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to