Databricks does not show matplotlib 3.2.2 figure, but instead shows: <Figure size ...x... with 1 Axes>

Viewed 1716

As stated in the title, when I use below code I don't get a figure, but I see: <Figure size 432x288 with 1 Axes> [<matplotlib.lines.Line2D at 0x7f7df9afca50>]

Code to reproduce behavior:

import numpy as np
import matplotlib.pyplot as plt

x = np.linspace(0, 2*np.pi, 50)
y = np.sin(x)

fig, ax = plt.subplots()
ax.plot(x, y)

I found similar questions on SO, all with the answer to use plt.show(), but that doesn't work.

My configuration:

  • Databricks Runtime version: 7.3 LTS (includes Apache Spark 3.0.1, Scala 2.12)
  • matplotlib==3.3.2

As stated by Databricks themselves, from version 6.5 and up, you no longer need to use %matplotlib inline. Whether I use that or not, it doesn't matter since I get the same output (no figure, but the axes statement).

Note: with matplotlib==3.2.1 I do see the figure, but I would like to know why it fails with version 3.2.2.

1 Answers

Just ran into the same problem, and while this is probably too late to help you, I'm posting the solution for others. By simply adding display(), the visualization rendered correctly.

import numpy as np
import matplotlib.pyplot as plt

x = np.linspace(0, 2*np.pi, 50)
y = np.sin(x)

fig, ax = plt.subplots()
ax.plot(x, y)
display()
Related