After checking other solutions out there, this is by far the best and simple too, without complicate callback mechanisms to regenerate the labels on the secondary axis, which still zooms properly.
After checking other solutions out there, this is by far the best and simple too, without complicate callback mechanisms to regenerate the labels on the secondary axis, which still zooms properly.
I had tried
set(gca, 'XTickMode', 'auto', 'XTickLabelMode', 'auto')
in the hope that labels would be updated automatically, but as a result the secondary axis becomes identical to the first!
Workaround, use manual xticks to start with, dense enough, before calling the function. But at least the new axis zooms properly! Well done Emmanuel!