如何解决matplotllib图形大小和xelatex之间的长度比例不匹配
我用
创建了一个pythonmatplotlib
图形
import matplotlib.pyplot as plt
xwidth = 418.25555 / 72 # conversion from in to pt
ywidth = 300 / 72 # conversion from in to pt
fig,ax = plt.subplots(figsize=[xwidth,ywidth])
ax.plot([1,2,3],[1,3])
ax.set_ylabel("Y-label")
ax.set_xlabel("X-label")
fig.savefig("test.pgf",bbox_inches="tight",pad=0)
我在XeLaTeX中通过xwidth
确定了\the\textwidth
,不得不将其转换为英寸。一英寸定义为72磅。但是,如果我将图形包含在文档中,则它与线宽不匹配:
\documentclass{scrartcl}
\usepackage{pgf}
\begin{document}
\begin{figure}
\input{test.pgf}
\end{figure}
Lorem ipsum dolor sit amet,consetetur sadipscing elitr,sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam\newline
Linewidth: \the\textwidth
\end{document}
我在做什么错了?
解决方法
我认为,当您使用bbox_inches="tight"
时,请缩短图形以消除空白,并且不要延伸轴。
在乳胶下,使用constrained_layout = true
或plt.tight_layout()
可以帮助我。
import matplotlib.pyplot as plt
xwidth = 418.25555 / 72 # conversion from in to pt
ywidth = 300 / 72 # conversion from in to pt
fig,ax = plt.subplots(figsize=[xwidth,ywidth],constrained_layout = True)
ax.plot([1,2,3],[1,3])
ax.set_ylabel("Y-label")
ax.set_xlabel("X-label")
fig.savefig("test.pdf")
或
import matplotlib.pyplot as plt
xwidth = 418.25555 / 72 # conversion from in to pt
ywidth = 300 / 72 # conversion from in to pt
fig,ywidth])
ax.plot([1,3])
ax.set_ylabel("Y-label")
ax.set_xlabel("X-label")
plt.tight_layout()
fig.savefig("test.pdf")
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。