多行字符串未与 ax.annotate 正确对齐

Multiline string not aligning properly with ax.annotate

我有一个多行字符串如下

annotation_string = """Excel file name: {0}
        Sheet name: {1}
        
        No.of Iterations: {2}
        Cp = {3}
        CpK = {4}
        
        Mean = {11}
        Standard Deviation = {12}
        
        The smallest simulated value is {5}
        The largest simulated value is {6}
        
        The 4sigma limit is from {7} to {8}
        The 5sigma limit is from {9} to {10}
        """.format(filename,sheet,iterations,round(cp,4),round(cpk,4),smallest_val,
                  largest_val,round(mean_minor_sigma[3],5),round(mean_sigma[3],5),
                   round(mean_minor_sigma[4],5),round(mean_sigma[4],5),round(mittelwert,4),round(sigma,4))

我使用下面的代码将其绘制在绘图的轴上

        ax1.annotate(annotation_string, xy=(0.65, 0.65), xycoords='axes fraction',
                                                     backgroundcolor='r', fontsize=14,
                                                     horizontalalignment='left')

结果如下图。如您所见,从第二行开始的文本已向右移动。

但是,当我将 horizontalalignment='left' 更改为 horizontalalignment='right' 时。每行都正确对齐

我想要左对齐而不是右对齐。我怎样才能做到这一点?

我能够找到正确对齐的方法,下面更新了代码。 'plot' 代码完全没有变化。仅更改多行文本的公式。

注意:-显然开头的三引号后的''很重要(不知道为什么但是没有它,输出和以前一样)

import textwrap
annotation_string = textwrap.dedent("""\
        Excel file name: {0}
        Sheet name: {1}
        
        No.of Iterations: {2}
        Cp = {3}
        CpK = {4}
        
        Mean = {11}
        Standard Deviation = {12}
        
        The smallest simulated value is {5}
        The largest simulated value is {6}
        
        The 4sigma limit is from {7} to {8}
        The 5sigma limit is from {9} to {10}
        """).format(filename,sheet,millify(iterations),round(cp,4),round(cpk,4),smallest_val,largest_val,round(mean_minor_sigma[3],5),round(mean_sigma[3],5),round(mean_minor_sigma[4],5),round(mean_sigma[4],5),round(mittelwert,4),round(sigma,4))