有办法自定义 PyGMT 图例字体大小吗?

huangapple go评论85阅读模式
英文:

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

有办法自定义 PyGMT 图例字体大小吗?

英文:

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

有办法自定义 PyGMT 图例字体大小吗?

huangapple
  • 本文由 发表于 2023年5月22日 00:36:44
  • 转载请务必保留本文链接:https://go.coder-hub.com/76300912.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定