【问题标题】:Databricks does not show matplotlib 3.2.2 figure, but instead shows: <Figure size ...x... with 1 Axes>Databricks 不显示 matplotlib 3.2.2 图,而是显示:<Figure size ...x... with 1 Axes>
【发布时间】:2021-01-28 22:24:03
【问题描述】:

如标题所述,当我使用以下代码时,我没有得到数字,但我看到:&lt;Figure size 432x288 with 1 Axes&gt; [&lt;matplotlib.lines.Line2D at 0x7f7df9afca50&gt;]

重现行为的代码:

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)

我在 SO 上发现了类似的问题,答案都是使用plt.show(),但这不起作用。

我的配置:

  • Databricks 运行时版本:7.3 LTS(包括 Apache Spark 3.0.1、Scala 2.12)
  • matplotlib==3.3.2

As stated by Databricks themselves,从 6.5 及以上版本开始,您不再需要使用 %matplotlib inline。无论我是否使用它,都没有关系,因为我得到了相同的输出(没有数字,但是轴语句)。

注意:matplotlib==3.2.1 我确实看到了这个数字,但我想知道为什么它在 3.2.2 版本中失败。

【问题讨论】:

    标签: python matplotlib databricks


    【解决方案1】:

    刚刚遇到了同样的问题,虽然这可能为时已晚,无法帮助您,但我正在为其他人发布解决方案。只需添加display(),即可正确呈现可视化。

    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()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-01-21
      • 2019-03-20
      • 2016-07-02
      • 2016-03-19
      • 1970-01-01
      • 2021-06-08
      • 1970-01-01
      • 2014-11-15
      相关资源
      最近更新 更多