英文:
Is there a way to customize PyGMT legend font size?
问题
I'm trying to change the font size of the legend in this PyGMT program, but I can't seem to find how.
Here are the lines for the legend:
# 从txt文件读取地震台站
ETNA=pd.read_csv("/Users/user/Desktop/PyGmt/ETNA.txt", sep='\s+')
fig.plot(x=ETNA.LONG, y=ETNA.LAT, style="i0.15c", fill='red', pen="gray", label='81 ETNA')
# 图例
fig.legend(position='g-2.6/32+w2.4/1.5', box='+gwhite+p1p+i', S=1.3)
(Note: I've translated the comments, variable names, and the legend part of your PyGMT program.)
英文:
I'm trying to change the font size of the legend in this PyGMT program, but I can't seem to find how.
Here are the lines for the legend:
#read Seismic stations from txt file
ETNA=pd.read_csv("/Users/user/Desktop/PyGmt/ETNA.txt", sep='\s+')
fig.plot(x=ETNA.LONG, y=ETNA.LAT, style="i0.15c", fill='red', pen="gray", label='81 ETNA')
# Legend
fig.legend(position='g-2.6/32+w2.4/1.5',box='+gwhite+p1p+i', S=1.3)
答案1
得分: 0
Generally, the fontsize of all primary annotations can be adjusted in a pygmt.config()
call by FONT_ANNOT_PRIMARY
(see also here). To adjust the fontsize only within the legend you need to put the call into a with
statement:
import pygmt
fig = pygmt.Figure()
fig.basemap(projection="x2c", region=[0, 7, 3, 7], frame=True)
fig.plot(
data="@Table_5_11.txt",
style="c0.40c",
fill="lightgreen",
pen="faint",
label="Apples",
)
fig.plot(data="@Table_5_11.txt", pen="1.5p,gray", label="My lines")
fig.plot(data="@Table_5_11.txt", style="t0.40c", fill="orange", label="Oranges")
# adjust font size only for legend
with pygmt.config(FONT_ANNOT_PRIMARY="20p"):
fig.legend(position="JTR+jTR+o0.2c", box="+gwhite+pblack")
fig.show()
英文:
Generally, the fontsize of all primary annotations can be adjusted in a pygmt.config()
call by FONT_ANNOT_PRIMARY
(see also here). To adjust the fontsize only within the legend you need to put the call into a with
statement:
import pygmt
fig = pygmt.Figure()
fig.basemap(projection="x2c", region=[0, 7, 3, 7], frame=True)
fig.plot(
data="@Table_5_11.txt",
style="c0.40c",
fill="lightgreen",
pen="faint",
label="Apples",
)
fig.plot(data="@Table_5_11.txt", pen="1.5p,gray", label="My lines")
fig.plot(data="@Table_5_11.txt", style="t0.40c", fill="orange", label="Oranges")
# adjust font size only for legend
with pygmt.config(FONT_ANNOT_PRIMARY="20p"):
fig.legend(position="JTR+jTR+o0.2c", box="+gwhite+pblack")
fig.show()
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论