AttributeError: 'FITSFigure' object has no attribute 'set_tick_labels_font'

286 Views Asked by At

I am a beginner in programming. I am trying to produce two plots using APLpy and subplot and simple code.

The code is as following:

import matplotlib
matplotlib.use('Agg')

import aplpy
import matplotlib.pyplot as mpl

fig = mpl.figure(figsize=(15, 7))

f1 = aplpy.FITSFigure('snr.5500-drop.fits', figure=fig, subplot=[0.1,0.1,0.35,0.8])
f1.set_tick_labels_font(size='x-small')
f1.set_axis_labels_font(size='small')
f1.show_grayscale()

f2 = aplpy.FITSFigure('snr.2100-drop.fits', figure=fig, subplot=[0.5,0.1,0.35,0.8])
f2.set_tick_labels_font(size='x-small')
f2.set_axis_labels_font(size='small')
f2.show_grayscale()

f2.hide_yaxis_label()
f2.hide_ytick_labels()

fig.canvas.draw()

It gives me the error: AttributeError: 'FITSFigure' object has no attribute 'set_tick_labels_font'

Could you please help me?

Thanks in advance

1

There are 1 best solutions below

4
On

Refer the docs for FITSFigure. The error occurs because hide_yaxis_label and set_tick_labels_font methods dont exist in FITSFigure class so you cannot use them.

Change the code as follows :

f2.set_tick_labels_font to f2.tick_labels.set_font(size = 'small')

hide_yaxis_labels to axis_labels.hide_x()

hide_ytick_labels to tick_labels.hide_x()

Please read the documents for class/package before using it in your code.