WCSaxes does not modify the tick formatting to make tick labels bold
See original GitHub issueHi, I am trying to plot a test statistic map from a fits file. I am using MAC Sierra and python 2.7. My input code is as follows
import scipy.ndimage as ndimage
from matplotlib.cm import register_cmap, cmap_d
from matplotlib import pyplot as plt
from astropy.io import fits
from astropy.wcs import WCS
from astropy.nddata import Cutout2D
from astropy import units as u
from matplotlib import rc, rcParams
import numpy as np
rc('text',usetex=True)
rc('font',**{'family':'serif','serif':['Computer Modern']})
rcParams['text.latex.preamble'] = [r'\boldmath']
ds9b = {'red': lambda v : 4 * v - 1,
'green': lambda v : 4 * v - 2,
'blue': lambda v : np.select([v < 0.25, v < 0.5, v < 0.75, v <= 1],
[4 * v, -4 * v + 2, 0, 4 * v - 3])}
register_cmap('ds9b', data=ds9b)
cmap = plt.cm.get_cmap('ds9b')
name='XXXX'
image_file='TSMAP.fits'
RA_radio=1.431711E+02
DEC_radio=5.310925E+01
RA_gamma=143.135398743
DEC_gamma=53.0875594636
R95=0.04 # in degrees
R95=R95*20 # convert to pixel system, 1 pixel=0.05 degree
w = WCS(image_file)
x_rad,y_rad=w.all_world2pix(RA_radio,DEC_radio,0)
x_gam,y_gam=w.all_world2pix(RA_gamma,DEC_gamma,0)
hdu = fits.open(image_file)[0]
wcs = WCS(hdu.header)
position = (x_gam,y_gam)
size=200
cutout = Cutout2D(hdu.data, position, size)
fig=plt.figure()
ax = fig.add_subplot(1,1,1, projection=wcs)
cax1=ax.imshow(cutout.data, origin='lower', cmap=cmap)
cax = ndimage.gaussian_filter(hdu.data, sigma=2, order=0)
cax = ax.imshow(cax,origin='lower', cmap=cmap)
cbar=fig.colorbar(cax1)
cbar.ax.set_ylabel(r'{\bf Test Statistic}', fontsize=16)
cbar.ax.tick_params(labelsize=16)
lon = ax.coords[0]
lat = ax.coords[1]
circle1=plt.Circle((x_gam,y_gam),R95,color='k',fill=False, lw=1)
fig.gca().add_artist(circle1)
ax.scatter([x_rad],[y_rad], c='r', s=40, marker='+',
transform=ax.get_transform(WCS(hdu.header)),
label=r'{\bf radio position}')
ax.scatter([x_gam],[y_gam], c='limegreen', s=40,
marker='x',transform=ax.get_transform(WCS(hdu.header)),
label=r'{\bf optimized $\gamma$-ray position}')
leg=ax.legend(loc='upper right', scatterpoints = 1, markerscale=2.,fontsize=16)
leg.get_frame().set_alpha(0.0)
for text in leg.get_texts():
plt.setp(text, color = 'w')
lon.set_axislabel(r'{\bf Right Ascension}', fontsize=16)
lat.set_axislabel(r'{\bf Declination}', fontsize=16)
lon.set_ticks(size=6, color='white')
lat.set_ticks(size=6, color='white')
lon.set_major_formatter('d')
lat.set_major_formatter('d')
lon.set_ticklabel(size=18)
lat.set_ticklabel(size=18)
lon.display_minor_ticks(True)
lat.display_minor_ticks(True)
lat.set_minor_frequency(5)
ax.set_title(r'{\bf %s}' %name, fontsize=16)
plt.savefig('%s_TSMAP.eps' %name, format='eps', dpi=600, bbox_inches='tight')
As can be seen, I can make axes labels bold using the latex style {\bf }. However, when trying to do the same with tick labels (using set_major_formatter), it throws the error ValueError: Invalid format: {\bf d}
Please help in this regard and please let me know if I need to provide more information.
Issue Analytics
- State:
- Created 6 years ago
- Comments:8 (6 by maintainers)
Top Results From Across the Web
Ticks, tick labels, and grid lines — Astropy v5.2
Once you have an axes object, the coordinates can either be accessed by index: ... The format of the tick labels can be...
Read more >How to set the matplotlib axes tick labels fontweight to bold?
Here is the answer for reasons behind this kind of error. It's because matplotlib avoids static positioning. Adding the following code just ...
Read more >How to make ticks labels (the numbers, not the axis labels ...
I have already made the axis labels bold. So don't tell me how to do this. Pleas focus on the ticklabels, which are...
Read more >Fixing Axes and Labels in R Plot Using Basic Options
Want all tick labels hozizontal; Want to reduce the sapce between axis and label… and so on. Let us try to do these...
Read more >How to Set Tick Labels Font Size in Matplotlib? - GeeksforGeeks
Create or import data. Plot a graph on data using matplotlib. Change the font size of tick labels. (this can be done by...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@pllim @astrofrog - Given that wcsaxes is quite a large submodule with its own issues, I took the liberty and created a
visualization.wcsaxes
label following the logic of theio
and thevo
modules.@astro-fermi I think this should be addressed by https://github.com/astropy/astropy/pull/7961 and available in the latest version of the astropy core package, but feel free to open a new issue if you are still having issues.