我正在使用matplotlib和乳胶标签作为轴,标题和颜色条标签
虽然它在大多数情况下都非常好用,但是当你使用\ text时,它会有一些问题.
一个非常简单的例子.
from matplotlib import pyplot as plt
plt.plot([1,2,3])
plt.title(r"$f_{\text{cor, r}}$")
plt.show()
Run Code Online (Sandbox Code Playgroud)
这将导致错误消息,如:
IPython/core/formatters.py:239: FormatterWarning: Exception in image/png formatter:
f_{\text{1cor, r}}
^
Unknown symbol: \text (at char 3), (line:1, col:4)
FormatterWarning,
Run Code Online (Sandbox Code Playgroud)
有没有一种简单的方法在那里使用\ text?
我正在尝试将颜色条添加到由两个具有相同宽高比的子图组成的图中,即set_aspect('equal'):

用于创建此图的代码可以在此IPython笔记本中找到.
使用下面显示的代码(以及笔记本中的代码)创建的图像是我可以获得的最佳结果,但它仍然不是我想要的.
plt.subplot(1,2,1)
plt.pcolormesh(rand1)
plt.gca().set_aspect('equal')
plt.subplot(1,2,2)
plt.pcolormesh(rand2)
plt.gca().set_aspect('equal')
plt.tight_layout()
from mpl_toolkits.axes_grid1 import make_axes_locatable
divider = make_axes_locatable(plt.gca())
cax = divider.append_axes("right", size="5%", pad=0.05)
plt.colorbar(cax=cax)
Run Code Online (Sandbox Code Playgroud)

这个问题似乎有关:
我写了一个小程序,它使用函数指针进行一些数值计算.
double polynom(const int j, const double xi) {
return pow(xi, j);
}
/**
* Calculate the legendre_polynom l_end on a certain position xi.
*/
double legendre_polynom(const int l_end, const double xi) {
vector <double> p_l(l_end+1);
p_l[0] = 1.0;
p_l[1] = xi;
for (int x = 2; x <= l_end; x++) {
// p_l = ((2x-1) * p_{x-1} - (x-1) * p_{x-2}) / l
p_l[x] = ((2 * x - 1) * p_l[x - 1] - (x - 1) * …Run Code Online (Sandbox Code Playgroud) 如果你需要解析一些有或没有某些条目的XML,你通常会得到这样的模式:
planet = system.findall('.//planet')
row['discoveryyear'] = int(planet.findtext("./discoveryyear")) if planet.findtext("./discoveryyear") else None
Run Code Online (Sandbox Code Playgroud)
有没有更好的方法呢?我想避免第二个planet.findtext调用,但也不想写另一行文本来存储变量