Created
July 16, 2011 16:43
-
-
Save pmarshwx/1086530 to your computer and use it in GitHub Desktop.
Demonstrates bug in the tick-labels of a colorbar in axes_grid1 ImageGrid
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
from matplotlib.pyplot import figure, scatter, colorbar | |
from matplotlib.colors import ListedColormap, BoundaryNorm | |
def get_colors(): | |
values = [0., 0.01, 0.1, 0.25, 0.5, 0.75, 1., 1.25, 1.5, 1.75, 2., 2.5, 3., | |
4., 5., 6., 7., 8., 9., 10., 11., 12., 13., 14., 15.] | |
colors = ["#FFFFFF", "#7FFF00", "#00CD00", "#008B00", "#104E8B", "#1E90FF", | |
"#00B2EE", "#00EEEE", "#8968CD", "#912CEE", "#8B008B", "#8B0000", | |
"#CD0000", "#EE4000", "#FF7F00", "#CD8500", "#FFD700", "#EEEE00", | |
"#FFFF00", "#7FFF00", "#00CD00", "#008B00", "#104E8B", "#1E90FF", | |
"#00B2EE"] | |
cmap = ListedColormap(colors[:-1]) | |
cmap.set_over(colors[-1]) | |
cmap.set_under(colors[0]) | |
normer = BoundaryNorm(values, cmap.N) | |
return cmap, normer | |
def test_isolevels(): | |
cmap, normer = get_colors() | |
x = y = c = np.arange(-1.0, 20, 1) | |
art = scatter(x,y,c=c, s=50, cmap=cmap, norm=normer) | |
cbar = colorbar(art) | |
return art.figure | |
def axgrid_test(): | |
from mpl_toolkits.axes_grid1 import ImageGrid | |
cmap, normer = get_colors() | |
fig = figure() | |
grid = ImageGrid(fig, 111, nrows_ncols = (1, 1), cbar_mode="each") | |
ax = grid[0] | |
x = y = c = np.arange(-1.0, 20, 1) | |
art = ax.scatter(x,y,c=c, s=50, cmap=cmap, norm=normer) | |
cbar = ax.cax.colorbar(art) | |
return art.figure | |
if __name__ == '__main__': | |
from pylab import show | |
fig1 = test_isolevels() | |
fig1.suptitle('Correct Colorbar Y-Tick Labels') | |
fig2 = axgrid_test() | |
fig2.suptitle('Incorrect Colorbar Y-Tick Labels') | |
show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment