如何控制matplotlib中的宽度和高度部分?

2024-05-19 15:39:20 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在准备一篇论文提交给一家杂志。在作者的指南中,他们说图像的格式是(除其他外)3:2(宽度和高度的比例)。我正在使用matplotlib绘制图形,我希望得到一个.eps格式的图像,并以这个比例(3:2)将它们放入latex文件中,但要确保该功能。我只是想知道我是否做对了

import numpy as np 
import matplotlib.pyplot as plt 
from random import randint, uniform,random
import random
import math

plt.rcParams['font.family'] = "Times New Roman" #Fount size.
plt.rcParams["figure.figsize"] = (30,20)        #width and height prportion

variables=[1563,6004,26406,52631,95580,183615,480500,1030582]
restricciones=[3538,15459,68886,155116,285660,603255,1709703,3694572]
instancias=['$I_{1}$','$I_{2}$','$I_{3}$','$I_{4}$','$I_{5}$','$I_{6}$','$I_{7}$','$I_{8}$']
plt.plot(instancias,variables,'#828282',marker='o',label="Number of decision variables")
plt.plot(instancias,restricciones,'#1E1E1E',marker='^',label="Number of constraints")
plt.grid()
plt.xlabel("Instances")
plt.ylabel("Units generated")
plt.legend(loc=0)
plt.ticklabel_format(style='sci', axis='y', scilimits=(0,0))
plt.savefig("test.eps",dpi=1200)
plt.show()

使用plt.rcParams[“figure.figsize”]=(30,20),确保在使用latex文档中生成的.eps文件时满足此比例(30:20=3:2=1.5)?提前谢谢


Tags: 文件图像importmatplotlibas格式pltrandom
2条回答

图的变化方向:

fig = plt.figure(figsize=(1,2))
plt.scatter(range(5), range(5))

enter image description here

fig = plt.figure(figsize=(2,2))
plt.scatter(range(5), range(5))

enter image description here

fig = plt.figure(figsize=(2,1))
plt.scatter(range(5), range(5))

enter image description here

子批次的变化方向

set_aspect是你的朋友:

plt.scatter(range(5), range(5))
plt.gca().set_aspect(.1)

enter image description here

plt.scatter(range(5), range(5))
plt.gca().set_aspect(1)

enter image description here

plt.scatter(range(5), range(5))
plt.gca().set_aspect(10)

enter image description here

相关问题 更多 >