[英]Length scale between matplotllib figure size and xelatex doesn't match
我創建了一個 python matplotlib
圖
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,2,3])
ax.set_ylabel("Y-label")
ax.set_xlabel("X-label")
fig.savefig("test.pgf", bbox_inches="tight", pad=0)
我通過xwidth
\\the\\textwidth
了 xwidth 並且必須將其轉換為英寸。 一英寸定義為 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,2,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,ax = plt.subplots(figsize=[xwidth, ywidth])
ax.plot([1,2,3],[1,2,3])
ax.set_ylabel("Y-label")
ax.set_xlabel("X-label")
plt.tight_layout()
fig.savefig("test.pdf")
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.