From: Jim V. <Jim...@no...> - 2010-02-24 11:48:43
|
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 > On Tue, Feb 23, 2010 at 11:03 AM, Jim Vickroy <Jim...@no...> 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...@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: >> >> 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® 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 >> Mat...@li... >> https://lists.sourceforge.net/lists/listinfo/matplotlib-users >> >> >> > > ------------------------------------------------------------------------------ > Download Intel® 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 > Mat...@li... > https://lists.sourceforge.net/lists/listinfo/matplotlib-users > |