Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 设置matplotlib热图注释格式时出错_Python_Python 3.x_Matplotlib_Format_Heatmap - Fatal编程技术网

Python 设置matplotlib热图注释格式时出错

Python 设置matplotlib热图注释格式时出错,python,python-3.x,matplotlib,format,heatmap,Python,Python 3.x,Matplotlib,Format,Heatmap,我正在尝试格式化matplotlib热图上的批注。这是我的密码 x_axis_titles = ["Recession Probibility"] spread = array([[3.0], [5.0], [10.0], [15.0], [20.0], [25.0], [30.0],

我正在尝试格式化matplotlib热图上的批注。这是我的密码

x_axis_titles = ["Recession Probibility"]

spread = array([[3.0],
                [5.0],
                [10.0],
                [15.0],
                [20.0],
                [25.0],
                [30.0],
                [40.0],
                [50.0],
                [60.0],
                [70.0],
                [80.0],
                [90.0]])

spread_divisions = [1.35, 1.21, 0.76, 0.46, 0.22, 0.02, -0.17, -0.50, -0.82, -1.13, -1.46, -1.85, -2.40]
f = Figure(dpi=100)
ax = f.add_subplot(1,1,1)
ax.imshow(spread, cmap="bwr")

f.set_figwidth(3, forward=True)
f.set_figheight((root.winfo_height() / 100) - 4.0, forward=True)
ax.tick_params(axis='x', which='both', bottom=False, top=False, labelbottom=False)
ax.set_yticks(arange(len(spread_divisions)))
ax.set_yticklabels(spread_divisions)
for i in range(len(spread)):
    for j in range(len(x_axis_titles)):
        ax.text(j, i, '%.1f%' % spread[i, j], ha="center", va="center", color="w")

ax.set_title("Recession Probability\n\nCurrent Spread: " + str(round(dcf_data[9][-1] - (dcf_data[8][-1] * 100), 2)))

canvas = FigureCanvasTkAgg(f, master=dashboard_page)
canvas.show()
canvas.get_tk_widget().grid(row=1, column=0, columnspan=2, sticky=tkinter.W, padx=(10), pady=(5,5))
然而,我收到了这个错误:
ValueError:不完整的格式
,它来自嵌套for循环中的行
ax.text(j,I,'.1f%'%spread[I,j],ha=“center”,va=“center”,color=“w”)

我试图在下图中的热图文本中添加百分比符号。


感谢您的帮助!谢谢。

使用以下代码修复了此问题:

for i in range(len(spread)):
        for j in range(len(x_axis_titles)):
            ax.text(j, i, spread[i, j], ha="center", va="center", color="w")

for t in ax.texts: 
    t.set_text(t.get_text() + "%")

您可能想阅读一些python文档,了解如何使用precentage formatter,例如。