Description
To help us understand and resolve your issue please check that you have provided
the information below.
-
Matplotlib version, Python version and Platform (Windows, OSX, Linux ...)
Matplotlib 1.51, Python 3.5.2 on Red Hat Enterprise Linux 6.5 -
How did you install Matplotlib and Python (pip, anaconda, from source ...)
Anaconda 1.5.1 (conda 4.2.9) -
If possible please supply a Short, Self Contained, Correct, Example
that demonstrates the issue i.e a small piece of code which reproduces the issue
and can be run with out any other (or as few as possible) external dependencies.
from matplotlib import pyplot as plt
from matplotlib.ticker import Formatter, MaxNLocator
ax = plt.plot([0, 1, 2, 3], [0, 1, 2, 3])[0].axes
ax.figure.subplots_adjust(bottom=0.3)
ax.set_xlabel('Axis1') # To demonstrate that labels can be set differently
ax2 = ax.twinx()
ax2.set_frame_on(True)
ax2.patch.set_visible(False)
ax2.yaxis.set_visible(False)
ax2.xaxis.set_visible(True)
ax2.spines['bottom'].set_position(('axes', -0.2)) # So far so good
ax2.set_xlabel('Axis2') # Surprisingly (or not), this works
class F(Formatter):
def __call__(self, x, pos=None):
return '%03d' % x
# This does not work as expected:
ax.xaxis.set_major_locator(MaxNLocator(integer=True)) # Both locators get modified
ax2.xaxis.set_major_formatter(F()) # Both formatters get modified
I suspect that this has something to do with the fact that Axis
has a Ticker
container for the attributes that are behaving inappropriately, and that they are not being copied correctly when the axis is twinned for some reason. I have not been able to trace this problem down yet, but with a few pointer from the experts, I'd probably be able to make a PR. Assuming this is actually an issue, of course.
- If this is an image generation bug attach a screenshot demonstrating the issue.
- If this is a regression (Used to work in an earlier version of Matplotlib), please
note where it used to work.