#python #matplotlib #astropy
Вопрос:
Я новичок в python и пытаюсь увеличить масштаб отображения карт, чтобы уменьшить пустое пространство
Я пытался использовать plt.tight_layout() и plt.add_subplots, но это не сработало
Это мой необработанный код
def flatten_header(header):
"""
Attempt to turn an N-dimensional fits header into a 2-dimensional header
Turns all CRPIX[>2] etc. into new keywords with suffix 'A'
"""
orig_wcs = wcs.WCS(header)
newheader = orig_wcs.celestial.to_header()
newheader['NAXIS'] = 2
newheader['NAXIS1'] = header['NAXIS{0}'.format(orig_wcs.wcs.lng 1)]
newheader['NAXIS2'] = header['NAXIS{0}'.format(orig_wcs.wcs.lat 1)]
newheader['BMAJ'] = header['BMAJ']
newheader['BMIN'] = header['BMIN']
newheader['BPA'] = header['BPA']
return newheader
def create_image(output_fitsname,mmb_name):
#query = "select mmb_ra_decimal as mmb_ra_decimal,mmb_dec_decimal from mmb_full.mmb_dust_master where concat(round(mmb_gal_long,3),if(mmb_gal_lat > 0, ' ',''), round(mmb_gal_lat,3)) = '" str(mmb_name) "' order by mmb_name limit 1"
query = "select mmb_ra_decimal as mmb_ra_decimal,mmb_dec_decimal from mmb_dust_master where concat( right(left(mmb_name,8),7),if(mmb_gal_lat > 0, ' ','-'), right(mmb_name,5)) = '" str(mmb_name) "' order by mmb_name limit 1"
print(query)
mmb_positions = pd.read_sql_query(query, con = mydb )
#mmb_positions = pd.read_sql_query(query.format(mmb_name), con = conn )
A1 =(mmb_positions['mmb_ra_decimal'])
B1 =(mmb_positions['mmb_dec_decimal'])
print(mmb_name)
print('these are the positions', A1[0], B1[0])
#plt.plot(A1,B1, markersize = 2, marker = '.',color='yellow', linestyle = 'none')
figure = aplpy.FITSFigure(output_fitsname) # Create a figure using the first item in the hdulist
figure.show_markers(A1[0], B1[0], edgecolor='lightblue', facecolor='none',
marker='o', s=250, alpha=0.95,coords_frame='world', linewidth = 4)
query = "select t2.ra_5ghz as ra_5ghz, t2.dec_5ghz as dec_5ghz from C2186_SOURCES t1, atlas_rms_radio_cat t2 where t1.source_name = '" str(mmb_name) "' and power(power(t1.gal_long-t2.gal_long_5GHz,2) power(t1.gal_lat-t2.gal_lat_5GHz,2),0.5)*3600 < 100 and t2.ra_5ghz is not null"
print(query)
radio_positions = pd.read_sql_query(query, con = mydb )
#mmb_positions = pd.read_sql_query(query.format(mmb_name), con = conn )
A1 =(radio_positions['ra_5ghz'].dropna())
B1 =(radio_positions['dec_5ghz'].dropna())
print(mmb_name)
#print('these are the positions', A1[0], B1[0])
figure.show_markers(A1, B1, edgecolor='green', facecolor='none',
marker='o', s=100, alpha=0.95,coords_frame='world', linewidth = 4)
img_5ghz = f01[0].data
min_5ghz = np.nanmin(img_5ghz)
max_5ghz = np.nanmax(img_5ghz)
plt.rc('font', family='serif')
plt.rc('xtick', direction = 'in',labelsize='large')
plt.rc('ytick', direction = 'in',labelsize='large')
figure.show_colorscale(vmin= min_5ghz, vmax= max_5ghz,cmap='gist_heat',stretch = 'linear')
#figure.show_grayscale() # Show greyscale of the image
#figure.show_markers(ra[j], dec[j], edgecolor='red',marker='o', s =Major_axis[j], alpha=0.5, linewidth=3., facecolor='none')
#figure.show_ellipses(ra, dec, width =0.0057, height=0.0026)
#figure.show_circles(ra, dec,0.0057,edgecolor='green', facecolor='None', linewidth=3., alpha=0.7, coords_frame = 'world')
figure.show_ellipses(ra[j],dec[j], Minor_axis[j], Major_axis[j], angle=float(pa[j]),coords_frame = 'world', edgecolor='green', facecolor='None', linewidth=3., alpha=0.7)
#figure.show_ellipses()
#figure.add_beam(hatch='/////')
figure.add_beam()
figure.axis_labels.set_font(size=12, weight = 'bold')
figure.add_colorbar()
figure.colorbar.set_axis_label_text('Surface Brightness (Jy/beam)')
figure.colorbar.set_axis_label_font(size=12, weight = 'bold')
#figure.show_markers(xw=[catalogue.glon], yw=[catalogue.glat]) # Add markers from the catalogue
figure.save(output_filename) # Save figure to output file
return 1
for j in range(len(source_name)):
fits_filename = '/Users/' str(date) '/target_fits/' str(source_name[j]) '_' str(freq[j]) '.restor.fits'
output_fitsname = '/Users/C2186_Detections/' str(date) '/' str(source_name[j]) '_' str(freq[j]) '_' str(obs_date[j]) '.fits'
# Change these three as necessary
# catalogue_filename = "test.csv"
output_filename = '/Users//C2186_Detections/' str(date) '/' str(source_name[j]) '_' str(freq[j]) '_' str(obs_date[j]) '.png'
f01 = fits.open(fits_filename)
fheader01= f01[0].header
new_header = flatten_header(fheader01)
fits.writeto(output_fitsname,f01[0].data[0][0],header=new_header,overwrite=True)
create_image(output_fitsname,source_name[j])
Я прикрепил изображение вывода, которое я хотел бы увеличить!
Любая помощь будет очень признательна