首页 > 编程知识 正文

python教程matplotlib风格,python matplotlib使用教程

时间:2023-05-04 17:27:00 阅读:273631 作者:3783

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

matplotlib.figure.Figure.dpi方法

matplotlib库图形模块的dpi方法是每英寸点数的分辨率。

用法: fig.dpi

参数:此方法不接受任何参数。

返回:此方法以每英寸点数返回分辨率。

以下示例说明了matplotlib.figure中的matplotlib.figure.Figure.dpi函数:

范例1:

# Implementation of matplotlib function

import matplotlib.pyplot as plt

import numpy as np

fig = plt.figure()

nx = int(fig.get_figwidth() * fig.dpi)

ny = int(fig.get_figheight() * fig.dpi)

data = np.random.random((ny, nx))

plt.plot(data)

fig.suptitle('matplotlib.figure.Figure.dpi

function Example', fontweight ="bold")

plt.show()

输出:

范例2:

# Implementation of matplotlib function

import matplotlib.pyplot as plt

from matplotlib import collections, colors, transforms

import numpy as np

nverts = 50

npts = 100

r = np.arange(nverts)

theta = np.linspace(0, 2 * np.pi, nverts)

xx = r * np.sin(theta)

yy = r * np.cos(theta)

spiral = np.column_stack([xx, yy])

rs = np.random.RandomState(19680801)

xyo = rs.randn(npts, 2)

colors = [colors.to_rgba(c)

for c in plt.rcParams['axes.prop_cycle'].by_key()['color']]

fig, ax1 = plt.subplots()

col = collections.RegularPolyCollection(

7, sizes = np.abs(xx) * 10.0, offsets = xyo,

transOffset = ax1.transData)

trans = transforms.Affine2D().scale(fig.dpi / 72.0)

col.set_transform(trans)

ax1.add_collection(col, autolim = True)

col.set_color(colors)

fig.suptitle('matplotlib.figure.Figure.dpi() function

Example', fontweight ="bold")

plt.show()

输出:

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。