Y-labels shifted #1571

dopplershift opened this Issue Dec 7, 2012 · 2 comments


None yet
2 participants

dopplershift commented Dec 7, 2012 edited

Y-labels on colorbars are no longer centered any more. This is readily seen by running pylab_examples/contourf_demo.py. A git bisect shows the problem was caused by b9fba92.

This same commit has also resulted in shifted y-axis labels for axes created using the axes_grid toolkit. The easiest way to see this is to add y-axis labels to the axes_grid/demo_axes_grid.py. Tweaking that demo as below shows both problems:

import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1 import AxesGrid

def get_demo_image():
    import numpy as np
    from matplotlib.cbook import get_sample_data
    f = get_sample_data("axes_grid/bivariate_normal.npy", asfileobj=False)
    z = np.load(f)
    # z is a numpy array of 15x15
    return z, (-3,4,-4,3)

def demo_grid_with_each_cbar(fig):
    A grid of 2x2 images. Each image has its own colorbar.

    grid = AxesGrid(F, 111, # similar to subplot(122)
                    nrows_ncols = (2, 2),
                    axes_pad = 0.1,
                    label_mode = "1",
                    share_all = True,
    Z, extent = get_demo_image()
    for i in range(4):
        im = grid[i].imshow(Z, extent=extent, interpolation="nearest")
    grid[2].set_ylabel('Long y label')
    grid.cbar_axes[3].set_ylabel('Long Cbar label')

    # This affects all axes because we set share_all = True.
    grid.axes_llc.set_xticks([-2, 0, 2])
    grid.axes_llc.set_yticks([-2, 0, 2])

F = plt.figure(1, (5.5, 2.5))

F.subplots_adjust(left=0.05, right=0.98)



The commit makes sense as causing the problem, but I'm not sure why.

pwuertz was assigned Dec 7, 2012

@dopplershift dopplershift added a commit to dopplershift/matplotlib that referenced this issue Dec 12, 2012

@dopplershift dopplershift Fix shifted ylabels (#1571)
Account for rotation mode when setting axis label position. This is
used, for instance, when setting labels on colorbars.

dopplershift commented Dec 12, 2012

It turns out that the change to use "anchored" neglected to update the axis's set_label_position(). The commit (and PR) fix this directly. However, as discussed in the PR, I'm not sure this is the best way--axis ends up thinking way too much about text rotation.

@dopplershift dopplershift added a commit to dopplershift/matplotlib that referenced this issue Jan 16, 2013

@dopplershift dopplershift Fix shifted ylabels (#1571)
Force 'anchor' rotation mode when setting the label position,
and use the appropriate alignment for the Y-label position.

dopplershift commented Jan 16, 2013

Fixed by b2a80a7.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment