Matplotlib 朱莉娅:用PyPlot给每个子图分配数字字母?

Matplotlib 朱莉娅:用PyPlot给每个子图分配数字字母?,matplotlib,plot,julia,subplot,imshow,Matplotlib,Plot,Julia,Subplot,Imshow,我正在使用PyPlot包生成Julia中的图形。每个图都包含几个不同的图,我正在使用子图组织这些图。我想在每个子地块的左上角指定一个数字字母,以便第一个子地块在左上角获得一个加粗的“a”),第二个子地块在左上角获得一个加粗的“b”,依此类推。目前我的最佳尝试是使用标题: using PyPlot figure(1); subplots_adjust(hspace=0.4,wspace=0.4) subplot(221) ; imshow(rand(20,20)) ; title("a)",lo

我正在使用
PyPlot
包生成Julia中的图形。每个图都包含几个不同的图,我正在使用
子图组织这些图。我想在每个子地块的左上角指定一个数字字母,以便第一个子地块在左上角获得一个加粗的“a”),第二个子地块在左上角获得一个加粗的“b”,依此类推。目前我的最佳尝试是使用
标题

using PyPlot

figure(1);
subplots_adjust(hspace=0.4,wspace=0.4)
subplot(221) ; imshow(rand(20,20)) ; title("a)",loc="left",fontweight="bold") ; xlabel("x") ; ylabel("y")
subplot(222) ; imshow(rand(20,20)) ; title("b)",loc="left",fontweight="bold") ; xlabel("x") ; ylabel("y")
subplot(223) ; imshow(rand(20,20)) ; title("c)",loc="left",fontweight="bold") ; xlabel("x") ; ylabel("y")
subplot(224) ; imshow(rand(20,20)) ; title("d)",loc="left",fontweight="bold") ; xlabel("x") ; ylabel("y")
这似乎很管用。但理想情况下,数字字母应放置在数字上方略高的位置,并更靠近左侧(以便数字字母位于y轴标签的左侧)。有什么方法可以实现我的目标吗?

类似的东西(用python编写)


在Julia的pyplot中
figtext
有效吗?只需“文本”就可以了。
annotate
text
更好,你可以更好地控制放置。
import numpy as np
from itertools import count
fig, ax_lst = plt.subplots(2, 2)


def label_subplots(ax_lst, *, upper_case=True,
                   offset_points=(-5, -5)):
    start_ord = 65 if upper_case else 97
    for ax, lab in zip(np.ravel(ax_lst), (chr(j) for j in count(start_ord))):
        ax.annotate(lab, (1, 1),
                    xytext=offset_points,
                    xycoords='axes fraction',
                    textcoords='offset points',
                    ha='right', va='top')


label_subplots(ax_lst, upper_case=True)