Matplotlib Figure Class图类

Matplotlib Figure Class图类

Matplotlib Figure Class图类

  Matplotlib是 Python 中的一个库,它是 NumPy 库的数值数学扩展。figure模块提供了顶级的 Artist,即 Figure,它包含了所有的绘图元素。该模块用于控制所有绘图元素的子图和顶级容器的默认间距。

Matplotlib Figure Class图类
Matplotlib Figure Class图类

  Matplotlib 提供了创建图形的模块和函数。通过使用函数matplotlib.pyplot.figure()我们可以创建一个新图形。我们还可以通过更改图形的大小、颜色、dpi 等来更改图形的视觉外观。可以使用函数matplotlib.pyplot.figure().add_subplot()向图形添加子图,该函数将在一个图形上添加多个图同样的数字。

  推荐:Python中的import语句

matplotlib.figure.Figure() 类

  此类是所有绘图元素的顶级容器。Figure 实例通过作为 CallbackRegistry 实例的回调属性支持回调

  语法:

class matplotlib.figure.Figure(figsize=None, dpi=None, facecolor=None, edgecolor=None, linewidth=0.0, frameon=None, subplotpars=None, tight_layout=None, constrained_layout=None)

  参数:

  • figsize :此参数是以英寸为单位的图形尺寸(宽度、高度)。
  • dpi :此参数是每英寸的点数。
  • facecolor :此参数是图形补丁的facecolor。
  • edgecolor :此参数是图形补丁边缘颜色。
  • linewidth :此参数是框架的线宽。
  • frameon :该参数是抑制绘制图形背景补丁。
  • subplotpars :此参数是 Subplot 参数。
  • tight_layout :此参数用于调整子图参数。
  • constrained_layout :此参数用于调整绘图元素的位置。

  返回:此方法返回图形实例。

  推荐:Matplotlib面向对象接口

如何设置图形属性

  例子 1

import matplotlib.pyplot as plt

# Changing the size of the figure
plt.figure(figsize=(10,6))

x=[1,2,3,4,5,6]
y=[2,1,5,4,7,5]

plt.title('Changing the figure size')
plt.xlabel('x-axis')
plt.ylabel('y-axis')
plt.plot(x,y)

plt.show()
如何设置图形属性
Matplotlib Figure Class图类

  推荐:Matplotlib简单绘图

  例子 2

import matplotlib.pyplot as plt
from matplotlib.figure import Figure
from mpl_toolkits.axisartist.axislines import Subplot
import numpy as np


fig = plt.figure(facecolor ="green")
	
ax = Subplot(fig, 111)
fig.add_subplot(ax)
	
ax.axis["left"].set_visible(False)
ax.axis["top"].set_visible(False)

fig.suptitle('matplotlib.figure.Figure() class Example\n\n',
			fontweight ="bold")
	
plt.show()
matplotlib.figure.Figure() 类
Matplotlib Figure Class图类

  推荐:Matplotlib使用教程

给文章评分

晓得博客,版权所有丨如未注明,均为原创
晓得博客 » Matplotlib Figure Class图类

转载请保留链接:https://www.pythonthree.com/matplotlib-figure-class/

Claude、Netflix、Midjourney、Chatgpt Plus账号购买,ChatGPT API购买,优惠码XDBK,用户购买的时候输入优惠码可以打95折

Chatgpt-Plus注册购买共享账号
Kinsta-free-hosting主机
Kinsta-free-hosting主机
Elementor可视化创建WordPress网站
Elementor可视化创建WordPress网站
滚动至顶部