synchronization of ticks position in twinx plots

Hello,

In relation to the recent thread on pareto chart, I have a question with
regards to the synchronization of ticks location when using twinx plots.
This question may have been adressed in the past, but my Google search
on this topic was unfruitful. Sorry if this question was already answered.

Basically, when using twinx two plot two different data sets, the scale
of the data, in the general case, is to be different (thus the need for
twinx). However, adding a grid to such a twinx plot leads to a very
irregular placement because the ticks positions are not "synchronized".
(I pasted a quick example to illustrate the tick placement issue at the
end of this message)

Ideally, I would like that both axis share a common placement for the
ticks. Is there a way to do that ?

I guess this would require that the two ticks Locators share "some
algorithm" so that they would "agree" on the placement instead of
working separetely. Other option may be that one Locator could work as a
slave of the other one. (I'm just trying to draw a rough picture)

Best,
Pierre

quick example to illustrate the tick placement issue :

import matplotlib.pyplot as plt

ax1 = plt.subplot(111)
ax1.plot([1,2,3], 'bo-')
ax1.grid(True)

ax2 = plt.twinx(ax1)
ax2.plot([11,12], 'rs-')
ax2.grid(True)

ax1.set_xlim(-0.5,2.5)

plt.show()

Probably could have the two axes listen for an “xlim_changed” event, check to see if it belongs to its twin, and update itself accordingly (without emitting).

Ben Root

···

On Wed, Sep 26, 2012 at 5:58 AM, Pierre Haessig <pierre.haessig@…1709…> wrote:

Hello,

In relation to the recent thread on pareto chart, I have a question with

regards to the synchronization of ticks location when using twinx plots.

This question may have been adressed in the past, but my Google search

on this topic was unfruitful. Sorry if this question was already answered.

Basically, when using twinx two plot two different data sets, the scale

of the data, in the general case, is to be different (thus the need for

twinx). However, adding a grid to such a twinx plot leads to a very

irregular placement because the ticks positions are not “synchronized”.

(I pasted a quick example to illustrate the tick placement issue at the

end of this message)

Ideally, I would like that both axis share a common placement for the

ticks. Is there a way to do that ?

I guess this would require that the two ticks Locators share "some

algorithm" so that they would “agree” on the placement instead of

working separetely. Other option may be that one Locator could work as a

slave of the other one. (I’m just trying to draw a rough picture)

Best,

Pierre

quick example to illustrate the tick placement issue :

import matplotlib.pyplot as plt

ax1 = plt.subplot(111)

ax1.plot([1,2,3], ‘bo-’)

ax1.grid(True)

ax2 = plt.twinx(ax1)

ax2.plot([11,12], ‘rs-’)

ax2.grid(True)

ax1.set_xlim(-0.5,2.5)

plt.show()

I guess you mean "ylim_changed" event ?

(Maybe my description was not very clear, but the issue I'm having is
with respective placement of yticks on left and right sides.
xticks are the same, so no problem with these.)

Best,
Pierre

···

Le 26/09/2012 15:30, Benjamin Root a écrit :

Probably could have the two axes listen for an "xlim_changed" event,
check to see if it belongs to its twin, and update itself accordingly
(without emitting).

Correct… twinx should have them listen to each other’s ylim_changed, twiny should have them listen to each other’s xlim_changed. Thanks for catching that…

Ben Root

···

On Wed, Sep 26, 2012 at 11:07 AM, Pierre Haessig <pierre.haessig@…1709…> wrote:

Le 26/09/2012 15:30, Benjamin Root a écrit :

Probably could have the two axes listen for an “xlim_changed” event,

check to see if it belongs to its twin, and update itself accordingly

(without emitting).

I guess you mean “ylim_changed” event ?

(Maybe my description was not very clear, but the issue I’m having is

with respective placement of yticks on left and right sides.

xticks are the same, so no problem with these.)

Best,

Pierre