python 子图大小
In some cases, the automatic figure size generated by the matplotlib.pyplot is not visually good or there could be some non-acceptable ratio in the figure. So, rather than allowing a pyplot to decide the figure size, we can manually define the dimensions of the figure.
在某些情况下,由matplotlib.pyplot生成的自动图形大小在视觉上不佳,或者图形中可能存在某些不可接受的比例。 因此,我们可以手动定义图形的尺寸,而不是允许pyplot来确定图形的尺寸。
In this article, we are going to change figure size using an inbuilt function:
在本文中,我们将使用内置函数来更改图形大小 :
matplotlib.pyplot.figure(figsize)
Syntax:
句法:
matplotlib.pyplot.figure(figsize=(9,3))
# figsize(float, float)
width, height in inches.
1)宽身材 (1) Wide Figure)
2)高地 (2) Tall Plot)
3)小方形图 (3) Small Square Figure)
4)方形图 (4) Square Figure)
绘图图形大小的Python代码 (Python code for figure size of plot)
# Data Visualization using Python
# Figure Size
import numpy as np
import matplotlib.pyplot as plt
x = np.arange(50)
y = 2*x*x + 7*x - 14
# Example 1
plt.figure(figsize=(9,5))
# Leftmost
plt.plot(x, y, 'yo')
plt.title('Plot')
plt.ylabel('Function Vaule')
plt.xlabel('x-axis')
plt.show()
# Example 2
plt.figure(figsize=(6,9))
# Leftmost
plt.plot(x, y, 'yo')
plt.title('Plot')
plt.ylabel('Function Vaule')
plt.xlabel('x-axis')
plt.show()
# Example 3
plt.figure(figsize=(3,3))
# Leftmost
plt.plot(x, y, 'yo')
plt.title('Plot')
plt.ylabel('Function Vaule')
plt.xlabel('x-axis')
plt.show()
# Example 4
plt.figure(figsize=(7,7))
# Leftmost
plt.plot(x, y, 'yo')
plt.title('Plot')
plt.ylabel('Function Vaule')
plt.xlabel('x-axis')
plt.show()
Output:
输出:
Output is as figure
翻译自: https://www.includehelp.com/python/figure-size-of-plot.aspx
python 子图大小