From: Jim V. <Jim...@no...> - 2010-02-23 16:03:35
|
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...@no...' import numpy # http://numpy.scipy.org/ import matplotlib # http://matplotlib.sourceforge.net/index.html 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: 1. How do I get white color bar labels? 2. 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 |