亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

matplotllib圖形大小和xelatex之間的長度比例不匹配

matplotllib圖形大小和xelatex之間的長度比例不匹配

智慧大石 2023-07-27 10:27:05
我創建了一個 pythonmatplotlib圖形import matplotlib.pyplot as pltxwidth = 418.25555 / 72 # conversion from in to ptywidth = 300 / 72 # conversion from in to ptfig,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 中確定了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}結果如下:我究竟做錯了什么?
查看完整描述

1 回答

?
楊__羊羊

TA貢獻1943條經驗 獲得超7個贊

我認為,當您使用 時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")


查看完整回答
反對 回復 2023-07-27
  • 1 回答
  • 0 關注
  • 128 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號