我如何改变我的图像的大小,使其适合打印?
例如,我想使用A4纸,它的尺寸是11.7英寸乘8.27英寸。
我如何改变我的图像的大小,使其适合打印?
例如,我想使用A4纸,它的尺寸是11.7英寸乘8.27英寸。
当前回答
你需要提前创建matplotlib Figure和Axes对象,指定图形的大小:
from matplotlib import pyplot
import seaborn
import mylib
a4_dims = (11.7, 8.27)
df = mylib.load_data()
fig, ax = pyplot.subplots(figsize=a4_dims)
seaborn.violinplot(ax=ax, data=df, **violin_options)
其他回答
对于我的图(一个sns因子图),建议的答案并不能很好地工作。
因此我使用
plt.gcf().set_size_inches(11.7, 8.27)
就在与seaborn的情节之后(所以不需要传递一个斧头给seaborn或改变rc设置)。
首先导入matplotlib并使用它来设置图形的大小
from matplotlib import pyplot as plt
import seaborn as sns
plt.figure(figsize=(15,8))
ax = sns.barplot(x="Word", y="Frequency", data=boxdata)
这也会起作用。
from matplotlib import pyplot as plt
import seaborn as sns
plt.figure(figsize=(15,16))
sns.countplot(data=yourdata, ...)
一些尝试过的方法:
import seaborn as sns
import matplotlib.pyplot as plt
ax, fig = plt.subplots(figsize=[15,7])
sns.boxplot(x="feature1", y="feature2",data=df) # where df would be your dataframe
or
import seaborn as sns
import matplotlib.pyplot as plt
plt.figure(figsize=[15,7])
sns.boxplot(x="feature1", y="feature2",data=df) # where df would be your dataframe
你需要提前创建matplotlib Figure和Axes对象,指定图形的大小:
from matplotlib import pyplot
import seaborn
import mylib
a4_dims = (11.7, 8.27)
df = mylib.load_data()
fig, ax = pyplot.subplots(figsize=a4_dims)
seaborn.violinplot(ax=ax, data=df, **violin_options)