MatplotlibMatplotlib

用于显示 Matplotlib 图形的方法取决于群集正在运行的 Databricks Runtime 版本:The method for displaying Matplotlib figures depends on which version of Databricks Runtime your cluster is running:

  • Databricks Runtime 6.5 及更高版本:直接支持以内联方式显示图表。Databricks Runtime 6.5 and above: directly support displaying figures inline.
  • Databricks Runtime 6.4:调用 %matplotlib inline magic 命令。Databricks Runtime 6.4: Call the %matplotlib inline magic command.
  • Databricks Runtime 6.3:将群集配置为 spark.databricks.workspace.matplotlibInline.enabled = true,并调用 %matplotlib inline magic 命令。Databricks Runtime 6.3: Configure your cluster with spark.databricks.workspace.matplotlibInline.enabled = true and call the %matplotlib inline magic command.
  • Databricks Runtime 6.2 及更低版本:使用 display 函数。Databricks Runtime 6.2 and below: Use the display function.

以下笔记本演示如何在 Python 笔记本中显示 Matplotlib 图形。The following notebook shows how to display Matplotlib figures in Python notebooks.

Matplotlib Python 笔记本Matplotlib Python notebook

获取笔记本Get notebook

在更高的分辨率下呈现图像Render images at higher resolution

可以在 Python 笔记本中以标准分辨率的两倍呈现 matplotlib 图像,为高分辨率屏幕用户提供更好的可视化效果体验。You can render matplotlib images in Python notebooks at double the standard resolution, providing users of high-resolution screens with a better visualization experience. 在笔记本单元中设置以下项之一:Set one of the following in a notebook cell:

retina 选项:retina option:

%config InlineBackend.figure_format = 'retina'

from IPython.display import set_matplotlib_formats
     set_matplotlib_formats('retina')

png2x 选项:png2xoption:

%config InlineBackend.figure_format = 'png2x'

from IPython.display import set_matplotlib_formats
set_matplotlib_formats('png2x')

若要切换回标准分辨率,请将以下内容添加到笔记本单元:To switch back to standard resolution, add the following to a notebook cell:

set_matplotlib_formats('png')

%config InlineBackend.figure_format = 'png'