如何使用 Matplotlib 更改 Jupyter 笔记本中 matshow() 的 figsize?

matplotlibpythondata visualization

要更改 mathshow 的 figsize,我们可以在 figure 方法参数中使用 figsize,并在 matshow() 方法中使用 fignum。

步骤

  • 使用 figure() 方法创建新图形或激活现有图形。
  • 使用 Pandas 创建数据框。
  • 使用 ma​​tshow() 方法在新图形窗口中将数组显示为矩阵。
  • 参数 fignum 可以取 None、int 或 False 值
    • 如果为 *None*,则创建一个具有自动编号的新图形窗口。
    • 如果为非零整数,则使用给定的数字绘制到图形中。如果不存在,则创建一个。
    • 如果为 0,则使用当前轴(如果不存在,则创建一个)。
  • 要显示图形,请使用 show() 方法。

示例

import pandas as pd
from matplotlib import pyplot as plt
plt.rcParams["figure.figsize"] = [7.00, 3.50]
plt.rcParams["figure.autolayout"] = True
plt.figure()
df = pd.DataFrame({"col1": [1, 3, 5, 7, 1], "col2": [1, 5, 7, 9, 1]})
plt.matshow(df.corr(), fignum=1)
plt.show()

输出


相关文章