找到 10786 篇文章 关于 Python

在 Matplotlib 中为所有子图设置相同的坐标轴限制

Rishikesh Kumar Rishi
更新于 2021年6月1日 11:45:40

15K+ 阅读量

要在 matplotlib 中为所有子图设置相同的坐标轴限制,我们可以使用 subplot() 方法创建 4 个子图,其中 nrows=2、ncols=2 共享 x 和 y 轴。步骤设置图形大小并调整子图之间和周围的填充。在索引 1 处向当前图形添加一个子图。使用 set_xlim() 和 set_ylim() 方法设置 x 和 y 轴的视图限制。在轴 1(步骤 2)上绘制一条线。在索引 2 处向当前图形添加一个具有相同限制(步骤 3)的子图。在轴 2 上绘制一条线。在索引 3 处向当前图形添加一个子图,... 阅读更多

在 Matplotlib 中使用对数刻度绘制包含零值的图形

Rishikesh Kumar Rishi
更新于 2021年6月1日 11:45:00

1K+ 阅读量

要在 matplotlib 中使用对数刻度绘制包含零值的图形,我们可以使用 xscale() 和 yscale() 方法,并使用名为“symlog”的类。步骤设置图形大小并调整子图之间和周围的填充。使用 plot() 方法绘制两个包含零值的列表。使用名为“symlog”的类使用 yscale() 方法。使用名为“symlog”的类使用 xscale() 方法。要显示图形,请使用 show() 方法。示例from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True plt.plot([0, 1, 2, 0, 3], [1, 0, 2, 3, 5], marker='o', linestyle='-') plt.yscale('symlog') plt.xscale('symlog') plt.show()输出

在 Matplotlib 中调整文本背景透明度

Rishikesh Kumar Rishi
更新于 2021年6月1日 11:40:27

3K+ 阅读量

要在 matplotlib 中调整文本背景透明度,我们可以在 bbox 的字典中更改 alpha 值,其中 facecolor='red' 和 alpha='0.4'。步骤设置图形大小并调整子图之间和周围的填充。使用 numpy 创建 x 和 y 数据点。使用 plot() 方法绘制 x 和 y 数据点。现在使用 text() 方法使用 fontdict 和 bbox 字典在 x=-1.0 和 y=4.0 处调整文本背景。要显示图形,请使用 show() 方法。示例import numpy as np from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True x = np.linspace(-2, 2, 10) y = np.exp(x) plt.plot(x, y) plt.text(-1.0, 4.0, ... 阅读更多

如何在 Matplotlib 中的 Seaborn 线形图上绘制虚线?

Rishikesh Kumar Rishi
更新于 2021年6月1日 11:44:18

5K+ 阅读量

要在 Seaborn 线形图上绘制虚线,我们可以在 lineplot() 的参数中使用 linestyle="dashed"。步骤设置图形大小并调整子图之间和周围的填充。使用 numpy 创建 x 和 y 数据点。使用 lineplot() 方法,并在参数中使用 x 和 y 数据点以及 linestyle="dashed"。要显示图形,请使用 show() 方法。示例import seaborn as sns import numpy as np from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True x = np.random.rand(10) y = np.random.rand(10) ax = sns.lineplot(x=x, y=y, linestyle="dashed") plt.show()输出阅读更多

如何在 Matplotlib Python 金融图表中跳过空日期(周末)?

Rishikesh Kumar Rishi
更新于 2021年6月1日 11:44:01

1K+ 阅读量

要在 matplotlib 的金融图表中跳过周末,我们可以迭代数据帧中的时间,如果工作日是 5 或 6,则跳过绘图。步骤设置图形大小并调整子图之间和周围的填充。使用键 time 创建一个数据帧。迭代数据帧的压缩索引和时间。如果迭代的时间戳的工作日是 5 或 6,则不要绘制它们。除了 5 或 6 工作日之外,绘制点。设置 Y 轴的当前刻度位置。使用网格线绘制图形。要显示图形,请使用 show() 方法。示例import pandas as pd from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, ... 阅读更多

如何在 Matplotlib 中的数据坐标中在绘图外部编写注释?

Rishikesh Kumar Rishi
更新于 2021年6月1日 11:43:44

1K+ 阅读量

我们可以使用 annotate() 方法在绘图外部放置注释。步骤设置图形大小并调整子图之间和周围的填充。使用 numpy 创建 x 和 y 数据点。使用 subplots() 方法创建图形和一组子图。使用 scatter() 方法使用星形标记和铜色图绘制 x 和 y 数据点。要将注释放置在绘图外部,请相应地使用 xy 坐标元组。要显示图形,请使用 show() 方法。示例import numpy as np from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True x = np.random.rand(100) y = np.random.rand(100) fig, ax = plt.subplots() ax.scatter(x, y, ... 阅读更多

使用 Matplotlib 绘制离散值的直方图

Rishikesh Kumar Rishi
更新于 2021年6月1日 11:43:20

2K+ 阅读量

要使用 matplotlib 绘制离散值的直方图,我们可以使用 hist() 方法。步骤设置图形大小并调整子图之间和周围的填充。创建离散值的列表。使用 hist() 方法绘制数据,其中 bins=数据长度,edgecolor=黑色。要显示图形,请使用 show() 方法。示例from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True data = [1, 4, 2, 3, 5, 9, 6, 7] plt.hist(data, bins=len(data), edgecolor='black') plt.show()输出

在 Matplotlib 中仅绘制热图的上/下三角形

Rishikesh Kumar Rishi
更新于 2021年6月1日 11:43:04

1K+ 阅读量

要在 matplotlib 中仅绘制热图的上/下三角形,我们可以使用 numpy 获取掩码 2D 数组并将它们转换为图像以生成热图。步骤设置图形大小并调整子图之间和周围的填充。创建一个 5×5 维度的随机数据。使用 numpy.tri() 方法创建一个数组,在给定对角线及其下方为 1,其他位置为 0。使用掩码数组获取掩码 2D 数组数据(使用步骤 3)。使用 imshow() 方法将数据显示为图像,即在 2D 常规光栅上。要显示图形,请使用 show() 方法。示例import numpy as ... 阅读更多

是否可以控制 Matplotlib 标记方向?

Rishikesh Kumar Rishi
更新于 2021年6月1日 11:42:45

481 阅读量

要控制 matplotlib 标记方向,我们可以使用标记元组,其中包含边的数量、样式和标记的旋转或方向。步骤设置图形大小并调整子图之间和周围的填充。使用 numpy 创建 x 和 y 数据点。创建 10 个不同旋转的数组。压缩 x、y 和 i。迭代它们并使用 plot() 方法和标记元组绘制点。要显示图形,请使用 show() 方法。示例import numpy as np from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True x = np.random.rand(10) y = np.random.rand(10) i = np.linspace(0, 10, 10) for x, ... 阅读更多

如何在 Matplotlib 中更改阴影线的线宽?

Rishikesh Kumar Rishi
更新于 2021年6月1日 11:40:06

2K+ 阅读量

要在 matplotlib 中更改阴影线的线宽,我们可以在 params 中设置阴影线的线宽。步骤设置图形大小并调整子图之间和周围的填充。使用 numpy 创建 x 和 y=sin(x) 数据点。在绘图中设置阴影线的线宽。使用 scatter() 方法绘制 x 和 y 数据点,使用正方形标记,并带有“/”阴影,并设置线宽。要显示图形,请使用 show() 方法。示例import numpy as np from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True x = np.linspace(-5, 5, 25) y = np.sin(x) plt.rcParams['hatch.linewidth'] = 1 plt.scatter(x, y, ... 阅读更多

广告

© . All rights reserved.