xticks when using twinx()

Hello,

I to set custom xticks is usually used

fig = plt.figure()
ax1 = fig.add_subplot(xticks=[10,40,90])
plt.plot(range(100))

I now need to have a second y-axis and tried

fig = plt.figure()

ax1 = fig.add_subplot(xticks=[10,40,90])
plt.plot(range(100))

ax2 = plt.twinx()
plt.plot([x*x for x in range(100)])

which works fine, but i use the ability to manipulate the xticks.

Any help is highly appriciated.

Thank you, Mario.

Mario,

When you call fig.add_subplot as you are doing, ax1 is None. I'm not sure why, but you don't need to set the xticks there anyway. Change your call to be ax1 = fig.add_subplot(111) that way ax1 != None. Then plot, create ax2, plot. You can then set the xticks by calling ax1.set_xticks([10,40,90]) or equivalently ax2.set_xticks([10,40,90]).

Eric

···

-----Original Message-----
From: Mario Konschake [mailto:mario.konschake@…287…]
Sent: Monday, March 19, 2012 1:11 PM
To: matplotlib-users
Subject: [Matplotlib-users] xticks when using twinx()

Hello,

I to set custom xticks is usually used

fig = plt.figure()
ax1 = fig.add_subplot(xticks=[10,40,90])
plt.plot(range(100))

I now need to have a second y-axis and tried

fig = plt.figure()

ax1 = fig.add_subplot(xticks=[10,40,90])
plt.plot(range(100))

ax2 = plt.twinx()
plt.plot([x*x for x in range(100)])

which works fine, but i use the ability to manipulate the xticks.

Any help is highly appriciated.

Thank you, Mario.

-----------------------------------------------------------------------
-------
This SF email is sponsosred by:
Try Windows Azure free for 90 days Click Here
http://p.sf.net/sfu/sfd2d-msazure
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Looking at the code for Figure.add_subplot in figure.py, the first line is:

if not len(args): return

Why just silently fail if no position arguments are passed? At the very least shouldn't this print an error message? I'm not sure that I understand the rational for just swallowing an error this way. Anyone know why it does this?

Eric

···

-----Original Message-----
From: Moore, Eric (NIH/NIDDK) [F]
Sent: Monday, March 19, 2012 1:48 PM
To: matplotlib-users
Subject: Re: [Matplotlib-users] xticks when using twinx()

Mario,

When you call fig.add_subplot as you are doing, ax1 is None. I'm not
sure why, but you don't need to set the xticks there anyway. Change
your call to be ax1 = fig.add_subplot(111) that way ax1 != None. Then
plot, create ax2, plot. You can then set the xticks by calling
ax1.set_xticks([10,40,90]) or equivalently ax2.set_xticks([10,40,90]).

Eric