【问题标题】:AttributeError: 'FITSFigure' object has no attribute 'set_tick_labels_font'AttributeError:“FITSFigure”对象没有属性“set_tick_labels_font”
【发布时间】:2021-12-29 04:38:41
【问题描述】:

我是编程初学者。我正在尝试使用 APLpy 和 subplot 以及简单的代码生成两个图。

代码如下:

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()

它给了我错误:AttributeError: 'FITSFigure' object has no attribute 'set_tick_labels_font'

你能帮帮我吗?

提前致谢

【问题讨论】:

    标签: python subplot aplpy


    【解决方案1】:

    请参阅docs 了解 FITSFigure。出现该错误是因为 FITSFigure 类中不存在 hide_yaxis_labelset_tick_labels_font 方法,因此您无法使用它们。

    修改代码如下:

    f2.set_tick_labels_fontf2.tick_labels.set_font(size = 'small')

    hide_yaxis_labelsaxis_labels.hide_x()

    hide_ytick_labelstick_labels.hide_x()

    在您的代码中使用之前,请阅读类/包的文档。

    【讨论】:

    • 非常感谢您的快速回答!它可以工作,但显示一个新的相同错误,但对于隐藏命令:AttributeError:'FITSFigure'对象没有属性'hide_yaxis_labels'
    • 已编辑,应该可以解决错误
    • 我会的,再次感谢您!
    • 如果可行,请批准答案:)
    猜你喜欢
    • 1970-01-01
    • 2012-12-01
    • 2021-04-19
    • 2021-11-22
    • 1970-01-01
    • 1970-01-01
    • 2018-08-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多