マップをプロットするために、healpy のmollview()
関数 ( http://healpy.github.com/healpy/generated/healpy.visufunc.mollview.html ) を使用しています。カラーバーのタイトルとラベルを指定できますが、フォント サイズを変更する方法がわかりません。この質問を投稿するのに適切な場所ではない場合は申し訳ありません... helpy のプロジェクト ページで質問できる場所が見つかりませんでした。また、私には十分な評判がなく、これまで誰も healpy について質問したことがないため、質問に「healpy」のタグを付けることもできません。
3 に答える
別の遅い応答:
残念ながら、これは関数内のオブジェクトであるため、この問題にはrcParams
対応していません。units
text
hp.visufunc.mollview
import healpy as hp
import numpy as np
import matplotlib
fontsize = 20
d = np.arange(12*16**2)
hp.mollview(d, title='Hello', unit=r'T', notext=False, coord=['G','C'])
matplotlib.rcParams.update({'font.size':fontsize})
matplotlib.pyplot.show()
ご覧のとおり、単位と座標系に対応するテキスト オブジェクトは、別のテキスト処理システムを持っているだけなので、影響を受けません。gcf()
関数を使用してオブジェクトを変更することができます。
import healpy as hp
import numpy as np
import matplotlib
fontsize = 20
d = np.arange(12*16**2)
hp.mollview(d, title='Hello', unit=r'T', notext=False, coord=['G','C'])
matplotlib.rcParams.update({'font.size':fontsize})
matplotlib.pyplot.show()
f = matplotlib.pyplot.gcf().get_children()
HpxAx = f[1]
CbAx = f[2]
coord_text_obj = HpxAx.get_children()[0]
coord_text_obj.set_fontsize(fontsize)
unit_text_obj = CbAx.get_children()[1]
unit_text_obj.set_fontsize(fontsize)
matplotlib.pyplot.show()
(Warpigのコメントは私の評判が悪いのでコメントできません)
2021 年 7 月の時点で、 、 withおよびIndexError: list index out of range
を呼び出したときにも取得しています。私の回避策は、最初に図を作成してから更新することでした。HpxAx = f[1]
healphy=1.11.0
matplotlib==3.0.0
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import cm
import healpy as hp
matplotlib.rcParams.update({'font.size': 18}) # fontsize for colorbar's values
fontsize = 22
cm.magma.set_under("w") # set background to white
# create figure
d = np.arange(12*16**2)
hp.mollview(d, title='Hello', unit=r'T', notext=False, coord=['G','C'], cmap=cm.magma)
f = plt.gcf() # accessing the current figure...
CbAx = f.get_children()[2] # ... then the colorbar's elements
coord_text_obj = CbAx.get_children()[1] # [1] corresponds to the particular label of the
# colorbar, i.e. "Field value" in this case
coord_text_obj.set_fontsize(fontsize)
plt.show()
この場合、カラーバーのラベルのフォントサイズを 22 に増やし、カラーバーの極値を 18 に増やすことにのみ関心があることに注意してください。「赤道」ラベルは影響を受けません。Figure を保存する場合は、plt.show()
.
申し訳ありませんが、遅い答えですが、誰かがグーグルからこれを見つけた場合に役立ちます:
プロットの更新中のすべてのテキストのフォント サイズを変更できますrcParams
。
import matplotlib
matplotlib.rcParams.update({'font.size': 22})