在Python中调整图像大小可以通过以下几种方法实现:
1. 使用Pillow库:
from PIL import Image打开原始图片img = Image.open('image.jpg')设置新的尺寸new_size = (800, 600)调整尺寸resized_img = img.resize(new_size)保存调整后的图片resized_img.save('resized_image.jpg')
2. 使用Matplotlib库:
import matplotlib.pyplot as plt创建图形时设置尺寸plt.figure(figsize=(12, 5))绘制图形...保存图形plt.savefig('resized_figure.png', dpi=300)
3. 使用Seaborn库(在绘制图形时调整尺寸):
import seaborn as snsimport matplotlib.pyplot as plt绘制图形...设置图形尺寸plt.figure(figsize=(12, 5))调整布局plt.tight_layout()保存图形plt.savefig('resized_figure.png', dpi=300)
请根据您的需求选择合适的方法。

