【问题标题】:Length scale between matplotllib figure size and xelatex doesn't matchmatplotllib 图形大小和 xelatex 之间的长度比例不匹配
【发布时间】:2020-09-11 11:36:07
【问题描述】:

我创建了一个 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)

我在 XeLaTeX 中通过\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}

结果如下:

我做错了什么?

【问题讨论】:

  • 在 TeX 中,一个 pt 是 1/72.27 英寸。但是,在这种情况下,它只占大约半毫米,所以肯定还有其他东西。

标签: python matplotlib latex xelatex pgf


【解决方案1】:

我认为,当您使用bbox_inches="tight" 时,您会缩短图形以去除空白,并且不要延长轴。

使用 constrained_layout = trueplt.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")

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-15
    • 2016-07-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多