python - 有没有一种简单的方法可以让 matplotlib 文本框像图例一样默认浮动?
问题描述
在广泛阅读 matplotlib 文档后,我能够编写我想要的代码,但我很好奇是否有更简单的解决方案。我将在下面添加相关代码。
import matplotlib.pyplot as plt
from matplotlib.offsetbox import AnchoredText
li_green = "#6BA755"
li_grey = "#D7D7D7" # rgb hex-code for the grey outline around the legend box
ax.plot(data_date, cumsum_income, ".-", label="Raw")
ax.plot(data_date, exp_func(months, *popt), label="Fit", color=li_green)
str_fit_eqn = '\n'.join(("Fit Equation:",
r"%.2f$e^{%.2fx}$%.2f" % (popt[0], popt[1], popt[2]),
r"$R^2$= %.2f" % (r_squared,)))
props = dict(boxstyle='round', facecolor="white", edgecolor=li_grey) # these are the text box parameters
anchored_text = AnchoredText(str_fit_eqn, loc=4, frameon=False, prop=dict(bbox=props))
ax.add_artist(anchored_text)
ax.legend(loc="best")
plt.show()
表达我的问题的另一种方式是,是否有一个参数可以完成这个文本框的轮廓,或者我应该使用 AnchoredText 以外的其他东西吗?
解决方案
推荐阅读
- java - JasperReports 如何将一系列页面导出到文本文件?
- apache - 将 AJP 代理与 Apache 一起使用时未显示自定义错误页面
- .htaccess - 使用语言路径和单个 URL 的重定向在 htaccess 中重写到新域
- python - 使用 Keras 的顺序密集网络上的输入维度错误
- java - Spring bean 装饰没有歧义错误
- java - 谁能告诉我这段代码出了什么问题?
- android - Videoview url 不起作用,但在 WebView Android 中工作
- android - 如何自动将 App Bundle 发布到 Google Play 商店?
- python - 使用数组更改列中的所有熊猫数据框单元格
- php - Readfile 返回一个空文件