在 Matplotlib / Scipy 等中使用 Latex 时出现问题
我第一次尝试使用 matplotlib 和 scipy 制作数据的散点图时遇到了一些问题(变量太多,试图一次查看很多东西)。这是我的一些代码,运行得相当好......
import numpy
from scipy import *
import pylab
from matplotlib import *
import h5py
FileID = h5py.File('3DiPVDplot1.mat','r')
# (to view the contents of: list(FileID) )
group = FileID['/']
CurrentsArray = group['Currents'].value
IvIIIarray = group['IvIII'].value
PFarray = group['PF'].value
growthTarray = group['growthT'].value
fig = pylab.figure()
ax = fig.add_subplot(111)
cax = ax.scatter(IvIIIarray, growthTarray, PFarray, CurrentsArray, alpha=0.75)
cbar = fig.colorbar(cax)
ax.set_xlabel('Cu / III')
ax.set_ylabel('Growth T')
ax.grid(True)
pylab.show()
我尝试更改代码以包含乳胶字体和解释,但是,它们似乎都不适合我。这是一个不起作用的示例尝试:
import numpy
from scipy import *
import pylab
from matplotlib import *
import h5py
rc('text', usetex=True)
rc('font', family='serif')
FileID = h5py.File('3DiPVDplot1.mat','r')
# (to view the contents of: list(FileID) )
group = FileID['/']
CurrentsArray = group['Currents'].value
IvIIIarray = group['IvIII'].value
PFarray = group['PF'].value
growthTarray = group['growthT'].value
fig = pylab.figure()
ax = fig.add_subplot(111)
cax = ax.scatter(IvIIIarray, growthTarray, PFarray, CurrentsArray, alpha=0.75)
cbar = fig.colorbar(cax)
ax.set_xlabel(r'Cu / III')
ax.set_ylabel(r'Growth T')
ax.grid(True)
pylab.show()
我使用 fink 安装的 python26 以及 scipy matplotlib 等的相应包。我一直在使用 iPython 和手动工作而不是 python 中的脚本。
由于我对 python 和 scipy 完全陌生,所以我确信我犯了一些愚蠢的简单错误。请赐教!我非常感谢您的帮助!
I'm having some issues with my first attempts at using matplotlib and scipy to make some scatter plots of my data (too many variables, trying to see many things at once). Here's some code of mine that is working fairly well...
import numpy
from scipy import *
import pylab
from matplotlib import *
import h5py
FileID = h5py.File('3DiPVDplot1.mat','r')
# (to view the contents of: list(FileID) )
group = FileID['/']
CurrentsArray = group['Currents'].value
IvIIIarray = group['IvIII'].value
PFarray = group['PF'].value
growthTarray = group['growthT'].value
fig = pylab.figure()
ax = fig.add_subplot(111)
cax = ax.scatter(IvIIIarray, growthTarray, PFarray, CurrentsArray, alpha=0.75)
cbar = fig.colorbar(cax)
ax.set_xlabel('Cu / III')
ax.set_ylabel('Growth T')
ax.grid(True)
pylab.show()
I tried to change the code to include latex fonts and interpreting, none of it seems to work for me, however. Here's an example attempt that didn't work:
import numpy
from scipy import *
import pylab
from matplotlib import *
import h5py
rc('text', usetex=True)
rc('font', family='serif')
FileID = h5py.File('3DiPVDplot1.mat','r')
# (to view the contents of: list(FileID) )
group = FileID['/']
CurrentsArray = group['Currents'].value
IvIIIarray = group['IvIII'].value
PFarray = group['PF'].value
growthTarray = group['growthT'].value
fig = pylab.figure()
ax = fig.add_subplot(111)
cax = ax.scatter(IvIIIarray, growthTarray, PFarray, CurrentsArray, alpha=0.75)
cbar = fig.colorbar(cax)
ax.set_xlabel(r'Cu / III')
ax.set_ylabel(r'Growth T')
ax.grid(True)
pylab.show()
I'm using fink installed python26 with corresponding packages for scipy matplotlib etc. I've been using iPython and manual work instead of scripts in python.
Since I'm completely new to python and scipy, I'm sure I'm making some stupid simple mistakes. Please enlighten me! I greatly appreciate the help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对于那些刚刚开始 scipy/matplotlib 的人来说,我发现这有助于查找有关我的安装的信息,因为我当前正在使用它...来自此 链接:
创建一个名为 simple_plot.py 的文件,其中包含最小脚本:
然后在命令行运行以下命令:
我收到的结果是:
我希望这对某人有帮助像我一样开始吧! :) 感谢大家对此的想法!
For those of you just starting scipy/matplotlib, I found this helpful in finding info about my installation as I'm currently using it... from this link:
Create a file called simple_plot.py which includes the minimal script:
then run the following at the command line:
The result I received was:
I hope this helps someone just starting out like me! :) Thanks for everyone's thoughts on this!
代码对我来说看起来不错,特别是 rc 命令。
检查此页面:使用 LaTeX 进行文本渲染。确保已安装 LaTeX、dvipng 和 Ghostscript。还要检查您正在使用哪个后端;你的可能不支持 LaTeX。
The code looks okay to me, particularly the
rc
commands.Check this page: Text Rendering with LaTeX. Make sure that LaTeX, dvipng, and ghostscript are installed. Also check which backend you are using; yours may not support LaTeX.