找到 784 篇文章 相关 数据可视化

如何使用 Matplotlib 限制 Seaborn countplot 中显示的组数?

Rishikesh Kumar Rishi
更新于 2021年5月15日 12:11:39

1K+ 阅读量

要限制 Seaborn countplot 中显示的组数,我们可以使用 countplot() 方法参数中的变量 group_count。步骤创建图形和两组子图。使用 Pandas 创建一个包含两个键的数据帧。初始化变量 group_count 以限制 countplot() 方法中的组计数。使用 countplot() 方法使用条形图显示每个分类箱中观测值的计数。调整子图之间和周围的填充。示例import pandas as pd import numpy as np import seaborn as sns from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True f, axes = plt.subplots(1, 2) df = ... 阅读更多

使用 Matplotlib 通过样本绘制概率密度函数

Rishikesh Kumar Rishi
更新于 2021年5月15日 12:11:07

2K+ 阅读量

要通过样本绘制概率密度函数,我们可以使用 numpy 获取 x 和 y 数据点。步骤使用 numpy 创建 x 和 p 数据点。使用 plot() 方法绘制 x 和 p 数据点。在某个范围内缩放 X 轴。要显示图形,请使用 show() 方法。示例import numpy as np from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True x = np.arange(-100, 100) p = np.exp(-x ** 2) plt.plot(x, p) plt.xlim(-20, 20) plt.show()输出

如何使用颜色条 Matplotlib 在 Python 中绘制二维矩阵?

Rishikesh Kumar Rishi
更新于 2021年5月15日 12:10:48

7K+ 阅读量

要使用颜色条在 Python 中绘制二维矩阵,我们可以使用 numpy 创建一个二维数组矩阵,并在 imshow() 方法中使用该矩阵。步骤使用 numpy 创建 data2D。使用 imshow() 方法将数据显示为图像,即在二维规则光栅上。使用 colorbar() 方法和 imshow() 标量映射图像为 ScalarMappable 实例 *mappable* 创建颜色条。要显示图形,请使用 show() 方法。示例import numpy as np from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True data2D = np.random.random((50, 50)) im = plt.imshow(data2D, cmap="copper_r") plt.colorbar(im) plt.show()输出阅读更多

如何使用 matplotlib.pyplot 更改表格的字体大小?

Rishikesh Kumar Rishi
更新于 2021年5月15日 12:17:24

7K+ 阅读量

要使用 matplotlib 更改表格的字体大小,我们可以使用 set_fontsize() 方法。步骤创建一个图形和一组子图,nrows=1 和 ncols=1。使用 numpy 创建随机数据。创建列值。使轴紧凑并关闭。初始化变量 fontsize 以更改字体大小。使用 set_font_size() 方法设置表格的字体大小。要显示图形,请使用 show() 方法。示例import numpy as np from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True fig, axs = plt.subplots(1, 1) data = np.random.random((10, 3)) columns = ("Column I", "Column II", "Column III") axs.axis('tight') axs.axis('off') the_table = axs.table(cellText=data, colLabels=columns, loc='center') the_table.auto_set_font_size(False) the_table.set_fontsize(10) plt.show()输出阅读更多

在 Matplotlib 中将 x 轴刻度标签居中于刻度标记之间

Rishikesh Kumar Rishi
更新于 2021年5月15日 12:17:52

800 阅读量

要将标签放置在两个刻度之间,我们可以采取以下步骤-加载一些样本数据,r。创建数组的副本,转换为指定类型。使用 subplots() 方法创建图形和一组子图。绘制日期和 r 样本数据。使用 set_major_locator() 和 set_minor_locator() 方法设置主要/次要刻度定位器。使用 set_major_locator() 和 set_minor_formatter() 方法设置主要/次要刻度格式化程序。现在,将刻度标签放置在中心。要显示图形,请使用 show() 方法。示例import numpy as np import matplotlib.cbook as cbook import matplotlib.dates as dates import matplotlib.ticker as ticker import matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = ... 阅读更多

在创建轴后更改 Matplotlib 子图大小/位置

Rishikesh Kumar Rishi
更新于 2021年5月15日 12:16:58

1K+ 阅读量

要更改创建轴后子图的大小或位置,我们可以采取以下步骤-使用 figure() 方法创建新图形或激活现有图形。使用 add_subplot() 方法将“~.axes.Axes”作为子图排列的一部分添加到图形中。使用 GridSpec() 类在图形中放置子图的网格布局。设置网格规格的位置。设置 subplotspec 实例。使用 add_subplot() 方法将“~.axes.Axes”作为子图排列的一部分添加到图形中,并使用 gridspec 实例。调整子图之间和周围的填充。要显示图形,请使用 show() 方法。示例from matplotlib import pyplot as plt from matplotlib import gridspec as ... 阅读更多

如何旋转 Matplotlib 注解以匹配线条?

Rishikesh Kumar Rishi
更新于 2021年5月15日 12:16:25

3K+ 阅读量

要旋转 matplotlib 注解以匹配线条,我们可以采取以下步骤-使用 figure() 方法创建新图形或激活现有图形。使用 add_subplot() 方法将“~.axes.Axes”作为子图排列的一部分添加到图形中。初始化变量 m(斜率)和 c(截距)。使用 numpy 创建 x 和 y 数据点。计算 theta 以进行文本旋转。使用 plot() 方法和 x 和 y 绘制线条。使用 text() 方法在直线上放置文本。要显示图形,请使用 show() 方法。示例import numpy as np from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True fig = plt.figure() ax ... 阅读更多

如何关闭所有打开的 pyplot 窗口(Matplotlib)?

Rishikesh Kumar Rishi
更新于 2021年5月15日 12:15:48

11K+ 阅读量

plt.figure().close(): 关闭图形窗口。close() 本身会关闭当前图形close(h),其中 h 是 Figure 实例,会关闭该图形close(num) 会关闭编号为 num 的图形close(name),其中 name 是字符串,会关闭具有该标签的图形close('all') 会关闭所有图形窗口示例from matplotlib import pyplot as plt fig = plt.figure() ax = fig.add_subplot() plt.show() plt.close()输出现在,在代码中交换语句“plt.show()”和“plt.close()”。您将无法看到任何图形作为输出,因为图形已关闭。

如何在 Matplotlib 中从图形中检索颜色条实例?

Rishikesh Kumar Rishi
更新于 2021年5月15日 12:10:26

584 阅读量

要在 matplotlib 中从图形中检索颜色条实例,我们可以使用 imshow 标量映射对象中的颜色条来检索颜色条实例。步骤获取 10×10 维数组的随机数据,数据点介于 -1 到 1 之间。使用 imshow() 方法将数据显示为图像,即在二维规则光栅上。为 ScalarMappable 实例 *mappable* 创建颜色条,并使用 imshow() 对象。要显示图形,请使用 show() 方法。示例import numpy as np from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True data = np.random.randint(-1, 1, (10, 10)) im = plt.imshow(data, interpolation="nearest") cbar = plt.colorbar(im) plt.show()输出阅读更多

在 Matplotlib 中旋转每个子图的轴文本

Rishikesh Kumar Rishi
更新于 2021年5月15日 12:10:01

320 阅读量

为了旋转每个子图的轴文本,我们可以在参数中使用带旋转的文本。步骤创建一个新的图形或激活一个现有的图形。使用 add_subplot() 方法将“~.axes.Axes”添加到图形中作为子图排列的一部分。使用 subplots_adjust() 方法调整子图布局参数。使用 suptitle() 方法向图形添加居中的标题。设置轴的标题。设置绘图的 x 和 y 标签。创建具有某些坐标点的轴。向图形添加文本,并带有一些参数,如字体大小、字体粗细和添加旋转。绘制一个点,并使用一些文本和箭头注释该点。要显示… 阅读更多

广告
© . All rights reserved.