找到 34423 篇文章 关于编程

Matplotlib 散点图中参数 'c' 和 'cmap' 如何工作?

Rishikesh Kumar Rishi
更新于 2021-07-08 11:15:04

1K+ 阅读量

要了解 Matplotlib 散点图中参数 c 和 cmap 的行为,我们可以采取以下步骤:设置图形大小并调整子图之间和周围的填充。初始化一个变量 N 来存储样本数据数量。使用 numpy 创建 x 和 y 数据点。使用 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 N = 50 x = np.random.randn(N) y = np.random.randn(N) plt.scatter(x, y, c=x, ... 阅读更多

使用 Matplotlib 从字典创建多个箱线图并在同一张图上显示

Rishikesh Kumar Rishi
更新于 2021-07-08 11:12:31

2K+ 阅读量

要从字典创建多个箱线图并在同一张图上显示,我们可以采取以下步骤:设置图形大小并调整子图之间和周围的填充。创建一个包含两列的字典 dict。创建一个图形和一组子图。制作一个箱线图设置 x 轴刻度标签,使用 set_xticklabels() 方法要显示图形,请使用 show() 方法。示例from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True data = {'col1': [3, 5, 2, 9, 1], 'col2': [2, 6, 1, 3, 4]} fig, ax = plt.subplots() ax.boxplot(data.values()) ax.set_xticklabels(data.keys()) plt.show()输出阅读更多

如何在 Matplotlib 中的 Seaborn 箱线图中编辑须线、异常值、帽等属性?

Rishikesh Kumar Rishi
更新于 2021-07-08 11:11:38

501 阅读量

要编辑 Seaborn 箱线图中须线、异常值、帽等属性,我们可以采取以下步骤:设置图形大小并调整子图之间和周围的填充。使用 Pandas 创建一个数据帧。从 DataFrame 列创建箱线图。获取箱线图的异常值、箱体、中位数和须线数据。打印所有上述数据。要显示图形,请使用 show() 方法。示例import seaborn as sns import pandas as pd from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True df = pd.DataFrame(dict(age=[23, 45, 21, 15, 12])) _, bp = pd.DataFrame.boxplot(df, return_type='both') outliers = [flier.get_ydata() for flier ... 阅读更多

使用 Matplotlib 在饼图中绘制 Pandas DataFrame

Rishikesh Kumar Rishi
更新于 2021-07-08 11:09:40

362 阅读量

要使用 Matplotlib 在饼图中绘制 Pandas 数据帧,我们可以采取以下步骤:设置图形大小并调整子图之间和周围的填充。创建一个二维、大小可变、可能异构的表格数据的 DataFrame。使用 pie() 方法绘制活动索引的 DataFrame要显示图形,请使用 show() 方法。示例import pandas as pd from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True df = pd.DataFrame({'activities': ['sleep', 'exercise', 'work', 'study'],                                     'hours': [8, 1, 9, 6]}) df.set_index('activities').plot.pie(y='hours', legend=False,                                     autopct='%1.1f%%') plt.show()输出

如何强制 Matplotlib 将 X 轴上的值显示为整数?

Rishikesh Kumar Rishi
更新于 2021-07-08 11:08:54

16K+ 阅读量

要强制 matplotlib 将 X 轴上的值显示为整数,我们可以采取以下步骤:设置图形大小并调整子图之间和周围的填充。创建两个数据点列表 x 和 y。使用 plot() 方法绘制 x 和 y。为 X 轴上的整数刻度创建一个新列表。使用 math.floor() 和 math.ceil() 删除小数并仅在列表中包含整数。设置 x 和 y 标签。设置图形标题。要显示图形,请使用 show() 方法。示例import math from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True y ... 阅读更多

如何使用 Matplotlib 绘制 Pandas 数据帧的特定行?

Rishikesh Kumar Rishi
更新于 2021-07-08 11:07:44

9K+ 阅读量

要绘制 Pandas 数据帧的特定行,我们可以采取以下步骤:设置图形大小并调整子图之间和周围的填充。创建一个 Pandas 数据帧 df。它应该是一个二维、大小可变、可能异构的表格数据。绘制 Pandas 的行。使用 iloc() 函数切片 df 并打印特定行。要显示图形,请使用 show() 方法。示例from matplotlib import pyplot as plt import numpy as np import pandas as pd plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True df = pd.DataFrame(np.random.randn(10, 5), columns=list('abcde')) df.iloc[0:6].plot(y='e') print(df.iloc[0:6]) # plt.show()输出我们有 10 行 ... 阅读更多

在 Matplotlib 的实时绘图中移动 X 轴

Rishikesh Kumar Rishi
更新于 2021-07-08 11:05:03

1K+ 阅读量

要在 Matplotlib 的实时绘图中移动 X 轴,我们可以采取以下步骤:设置图形大小并调整子图之间和周围的填充。创建一个图形和一组子图。使用 numpy 创建 x 和 y 数据点。使用 plot() 方法绘制 x 和 y 数据点。通过重复调用一个名为 *animate* 的函数来制作动画,该函数在实时绘图期间移动 X 轴。要显示图形,请使用 show() 方法。示例import matplotlib.pylab as plt import matplotlib.animation as animation import numpy as np plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True fig, ax = plt.subplots() x = np.linspace(0, 15, 100) ... 阅读更多

动态更新 Matplotlib 中的条形图

Rishikesh Kumar Rishi
更新于 2021-07-08 11:02:49

3K+ 阅读量

要动态更新 Matplotlib 中的条形图,我们可以采取以下步骤:设置图形大小并调整子图之间和周围的填充。创建一个新图形或激活现有图形。创建一个数据点和颜色的列表。使用 bar() 方法绘制具有数据和颜色的条形。使用 FuncAnimation() 类,通过重复调用一个名为 animation 的函数来制作动画,该函数设置条形的高度和条形的 facecolor。要显示图形,请使用 show() 方法。示例import numpy as np from matplotlib import animation as animation, pyplot as plt, cm plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = ... 阅读更多

如何在 Matplotlib 中绘制更多类型的线条?

Rishikesh Kumar Rishi
更新于 2021-07-08 11:02:02

76 阅读量

要绘制 Matplotlib 中更多类型的线条,我们可以采取以下步骤:设置图形大小并调整子图之间和周围的填充。使用 numpy 创建 x 和 y 数据点。使用 plot() 方法绘制 x 和 y 数据点,并使用一系列虚线。要显示图形,请使用 show() 方法。示例from matplotlib import pyplot as plt import numpy as np plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True x = np.linspace(-10, 10, 100) y = np.sin(x) plt.plot(x, y, dashes=[1, 1, 2, 1, 3], linewidth=7, color='red') plt.show()输出

如何在 Matplotlib 中将图例移动到 Seaborn 散点图外部?

Rishikesh Kumar Rishi
更新于 2021-07-08 11:00:52

2K+ 阅读量

要将图例移动到 Seaborn 散点图外部,我们可以采取以下步骤:设置图形大小并调整子图之间和周围的填充。创建一个包含三列(column1、column2 和 column3)的 Pandas 数据帧。绘制一个可能有多个语义分组的散点图。要在绘图外部放置图例,请在 legend() 方法中使用 bbox_to_anchor。要显示图形,请使用 show() 方法。示例import matplotlib.pyplot as plt import pandas as pd import seaborn as sns plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True df = pd.DataFrame(dict(col1=[2, 1, 4],                       ... 阅读更多

广告
© . All rights reserved.