Formatting font size and type on colorbar tick labels.

4,066 views
Skip to first unread message

Andrew Thron

unread,
Aug 31, 2015, 9:00:04 PM8/31/15
to hyperspy-users
All, 

I am using plot(colorbar=True, scalebar=False, auto_contrast=True, axes_ticks=True, cmap='CMRmap', saturated_pixels=0) to create color images of parameters from a Lorentzian I fit to surface plasmons in my low loss spectra (basically an image of how the center or fwhm of the Lorentzian changes over a given sample area). I am trying to change the font size and font type for the tick marks in the colorbar, but I have been unable to figure out how to do this. 

I can change the font size and font type of the x and y labels by:

ticks_font = font_manager.FontProperties(family='Times New Roman', style='normal',
    size=14, weight='normal', stretch='normal')

a = gca()
for label in a.get_xticklabels():
    label.set_fontproperties(ticks_font)

for label in a.get_yticklabels():
    label.set_fontproperties(ticks_font)

but I cannot find out how to do this for the color axis. 

Any suggestions?

Cheers, 
Andrew 

Andrew Thron

unread,
Sep 3, 2015, 1:20:50 PM9/3/15
to hyperspy-users
I figured it out, but you have to use the imshow() function in matplotlib rather then the plot() function in hyperspy. The script I wrote is:

#Plotting the Surface Plasmon Center
img=load('Surface Plasmon Center.rpl')
p=img.data
import scipy
import matplotlib.pyplot as plt
from matplotlib import font_manager
img2=plt.imshow(p,extent=(0,400,0,400))
img2.set_cmap('jet')
img2.set_interpolation('none')

#insert a colorbar
b=plt.colorbar()

plt.xlabel('x (nm)',fontsize=20, fontname='Times New Roman')
plt.ylabel('y (nm)',fontsize=20, fontname='Times New Roman')
plt.title('Surface Plasmon Center', fontsize=24,fontname='Times New Roman')
fontProperties = {'family':'serif','serif':['Times New Roman'],
    'weight' : 'normal', 'size' : 16}
ticks_font = font_manager.FontProperties(family='Times New Roman', style='normal',
    size=14, weight='normal', stretch='normal')

#set the label of the colorbar
b.set_label('eV',size=18,family='Times New Roman',rotation='horizontal')

#Set the font type and size of the colorbar
for l in b.ax.yaxis.get_ticklabels():
    l.set_family("Times New Roman")
    l.set_size(14)

a = gca()
for label in a.get_xticklabels():
    label.set_fontproperties(ticks_font)
    

for label in a.get_yticklabels():
    label.set_fontproperties(ticks_font)
    

If anyone knows how to do this with the plot() function in hyperspy let me know. 

Cheers, 
Andrew 

Francisco de la Peña

unread,
Sep 4, 2015, 4:50:46 AM9/4/15
to hyperspy-users
The matplotlib colobar attribute is indeed a bit hidden in HyperSpy. You'll find it in: `img._plot.signal_plot._colorbar`.

To update the figure you can use: `img._plot.signal_plot.update()`

Francisco

--
You received this message because you are subscribed to the Google Groups "hyperspy-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hyperspy-user...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages