configuring colorbar labels on a black background

Hello,

I’m (unsuccessfully) trying to generate a figure (with a labeled
colorbar) having a black background.

Here is the code.

purpose = ‘demonstrate capability to create PNG with black background
including labeled color bar’

author = ‘’
import numpy # import matplotlib # matplotlib.use(‘Agg’) # – probably the fastest, non-GUI, rendering backend
import matplotlib.pyplot as plot #
import matplotlib.cm # color maps
import sys
assert sys.version == ‘2.6.4 (r264:75708, Oct 26 2009,
08:23:19) [MSC v.1500 32 bit (Intel)]’, sys.version
assert numpy.version == ‘1.4.0’, numpy.version
assert matplotlib.version == ‘0.99.1’, matplotlib.version
data_min = 0
data_max = 256
data = numpy.random.randint(data_max, size=(512,512))
rows_cnt, columns_cnt = data.shape
shape = rows_cnt, columns_cnt
x = numpy.empty(data.shape, dtype=int)
y = numpy.empty(data.shape, dtype=int)
x[:] = numpy.arange(rows_cnt)
y[:] = numpy.arange(columns_cnt)
XI, YI = numpy.meshgrid(x[0], y[0])
title = ‘this is the figure title’
plot.clf() # clear the figure
plot.title(title,color=‘white’,backgroundcolor=‘black’)
plot.axis(‘off’)
colormap = ‘gist_heat’
config = dict(cmap=eval(‘matplotlib.cm.%s’ % colormap),
vmin=data_min, vmax=data_max) # vmin,vmax specify a fixed (color-map)
scale
plot.pcolormesh(XI, YI, data, **config)
colorbar = plot.colorbar()

···

jim.vickroy@…259…

http://numpy.scipy.org/
http://matplotlib.sourceforge.net/index.html
http://matplotlib.sourceforge.net/backends.html
http://matplotlib.sourceforge.net/api/pyplot_api.html#matplotlib.pyplot

This seems to be a bug and I recommend you to file a bug.
This happens because Axis.set_ticklabels method only changes the
attributes of left (or bottom) tick labels.

Meanwhile, try

for t in colorbar.ax.get_yticklabels():
    t.set_color("w")

-JJ

···

On Tue, Feb 23, 2010 at 11:03 AM, Jim Vickroy <Jim.Vickroy@...259...> wrote:

Hello,

I'm (unsuccessfully) trying to generate a figure (with a labeled colorbar)
having a black background.

Here is the code.

_purpose_ = 'demonstrate capability to create PNG with black background
including labeled color bar'
_author_ = 'jim.vickroy@...259...'

import numpy # http://numpy.scipy.org/
import matplotlib # Matplotlib — Visualization with Python
matplotlib.use('Agg') # http://matplotlib.sourceforge.net/backends.html --
probably the fastest, non-GUI, rendering backend
import matplotlib.pyplot as plot #
http://matplotlib.sourceforge.net/api/pyplot_api.html#matplotlib.pyplot
import matplotlib.cm # color maps

import sys
assert sys.version == '2.6.4 (r264:75708, Oct 26 2009, 08:23:19)
[MSC v.1500 32 bit (Intel)]', sys.version
assert numpy.__version__ == '1.4.0', numpy.__version__
assert matplotlib.__version__ == '0.99.1', matplotlib.__version__

data_min = 0
data_max = 256
data = numpy.random.randint(data_max, size=(512,512))
rows_cnt, columns_cnt = data.shape
shape = rows_cnt, columns_cnt
x = numpy.empty(data.shape, dtype=int)
y = numpy.empty(data.shape, dtype=int)
x[:] = numpy.arange(rows_cnt)
y[:] = numpy.arange(columns_cnt)
XI, YI = numpy.meshgrid(x[0], y[0])

title = 'this is the figure title'
plot.clf() # clear the figure
plot.title(title,color='white',backgroundcolor='black')
plot.axis('off')
colormap = 'gist_heat'
config = dict(cmap=eval('matplotlib.cm.%s' % colormap), vmin=data_min,
vmax=data_max) # vmin,vmax specify a fixed (color-map) scale
plot.pcolormesh(XI, YI, data, **config)
colorbar = plot.colorbar()
##############################################################################################################################################################
# labels = ??? list of strings labels ???
labels = [str(i) for i in range(10)]
colorbar.ax.set_yticklabels(labels, color='white')
##############################################################################################################################################################
plot.imshow(data, interpolation='bilinear', cmap=config['cmap'],
origin='upper', extent=[0,rows_cnt,0,columns_cnt])
# plot.show() # interactive
filename = 'trial-plot-with-labeled-colorbar.png'
plot.savefig(filename, facecolor='black')
plot.close()

which generates a figure with a black background and invisible (black) color
bar labels.

I'm probably going about this completely wrong.

Questions:

How do I get white color bar labels?
How do I access the generated sequence of string labels (for use as the
first set_yticklabels parameter) rather than artificially defining a list of
labels?

Thanks,
-- jv

------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

Jae-Joon Lee wrote:


This seems to be a bug and I recommend you to file a bug.
This happens because Axis.set_ticklabels method only changes the
attributes of left (or bottom) tick labels.
Meanwhile, try
for t in colorbar.ax.get_yticklabels():
t.set_color("w")
-JJ

Thanks for the explanation and alternative which works just fine!

As per your suggestion, I have submitted a trouble report (2957923).
entitled: “set_yticklabels(labels, color=‘white’) ignored”

– jv

···

<Jim.Vickroy@…259…>jim.vickroy@…259…http://numpy.scipy.org/http://matplotlib.sourceforge.net/index.htmlhttp://matplotlib.sourceforge.net/backends.htmlhttp://matplotlib.sourceforge.net/api/pyplot_api.html#matplotlib.pyplothttp://p.sf.net/sfu/intel-sw-devMatplotlib-users@lists.sourceforge.nethttps://lists.sourceforge.net/lists/listinfo/matplotlib-usershttp://p.sf.net/sfu/intel-sw-devMatplotlib-users@lists.sourceforge.nethttps://lists.sourceforge.net/lists/listinfo/matplotlib-users