微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

尝试渲染乳胶时 Matplotlib 冻结

如何解决尝试渲染乳胶时 Matplotlib 冻结

我是 matplotlib 和 latex 的新手。我尝试在我的计算机上从他们的 website 本地 运行此示例:

import matplotlib
import matplotlib.pyplot as plt
import numpy as np

matplotlib.rcParams['text.usetex'] = True

fig,ax = plt.subplots()
# interface tracking profiles
N = 500
delta = 0.6
X = np.linspace(-1,1,N)
ax.plot(X,(1 - np.tanh(4 * X / delta)) / 2,# phase field tanh profiles
        X,(1.4 + np.tanh(4 * X / delta)) / 4,"C2",# composition profile
        X,X < 0,"k--")                        # sharp interface

# legend
ax.legend(("phase field","level set","sharp interface"),shadow=True,loc=(0.01,0.48),handlelength=1.5,fontsize=16)

# the arrow
ax.annotate("",xy=(-delta / 2.,0.1),xytext=(delta / 2.,arrowprops=dict(arrowstyle="<->",connectionstyle="arc3"))
ax.text(0,0.1,r"$\delta$",color="black",fontsize=24,horizontalalignment="center",verticalalignment="center",bBox=dict(Boxstyle="round",fc="white",ec="black",pad=0.2))

# Use tex in labels
ax.set_xticks([-1,1])
ax.set_xticklabels(["$-1$",r"$\pm 0$","$+1$"],color="k",size=20)

# Left Y-axis labels,combine math mode and text mode
ax.set_ylabel(r"\bf{phase field} $\phi$",color="C0",fontsize=20)
ax.set_yticks([0,0.5,1])
ax.set_yticklabels([r"\bf{0}",r"\bf{.5}",r"\bf{1}"],size=20)

# Right Y-axis labels
ax.text(1.02,r"\bf{level set} $\phi$",color="C2",fontsize=20,rotation=90,horizontalalignment="left",clip_on=False,transform=ax.transAxes)

# Use multiline environment inside a `text`.
# level set equations
eq1 = (r"\begin{eqnarray*}"
       r"|\nabla\phi| &=& 1,\\"
       r"\frac{\partial \phi}{\partial t} + U|\nabla \phi| &=& 0 "
       r"\end{eqnarray*}")
ax.text(1,0.9,eq1,fontsize=18,horizontalalignment="right",verticalalignment="top")

# phase field equations
eq2 = (r"\begin{eqnarray*}"
       r"\mathcal{F} &=& \int f\left( \phi,c \right) dV,\\ "
       r"\frac{ \partial \phi } { \partial t } &=& -M_{ \phi } "
       r"\frac{ \delta \mathcal{F} } { \delta \phi }"
       r"\end{eqnarray*}")
ax.text(0.18,0.18,eq2,fontsize=16)

ax.text(-1,.30,r"gamma: $\gamma$",color="r",fontsize=20)
ax.text(-1,.18,r"Omega: $\Omega$",color="b",fontsize=20)

plt.show()

当我第一次尝试时,它崩溃了,告诉我需要安装乳胶。所以,我安装了 texlive 并再次尝试。这次它没有崩溃,但窗口只是冻结并且没有显示任何内容。你知道如何运行这个例子吗?

我需要在本地运行它(不是在 ipython 或 jupyter 中),因为它是我正在处理的桌面项目的一部分。如果它可以帮助任何人弄清楚,我正在使用 Windows 10。提前致谢。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。