【问题标题】:matplotlib does not show plot()matplotlib 不显示 plot()
【发布时间】:2016-10-25 04:48:19
【问题描述】:

我尝试运行 plt.show() 但没有显示任何情节。我尝试了很多来自 stackoverflow 的解决方案,包括将 matplotlib 后端设置为 Qt4Agg、切换到其他后端(即 TkAgg、Agg)以及重新安装 matplotlib 包,但仍然没有解决问题。我尝试过但不起作用的一些解决方案是:

matplotlib does not show my drawings although I call pyplot.show()

Matplotlib.Pyplot does not show output; No Error

Why matplotlib does not plot?

Matplotlib does not show labels or numbers

下面是我尝试运行的代码:

plt.scatter(pf["age"], pf["friend_count"])
plt.xlabel = "age"
plt.ylabel = "friends count"
plt.title = "Facebook Friends count by Age"
plt.show()

运行plt.scatter(pf["age"], pf["friend_count"]) 代码时,会显示散点图,但没有标签和标题。运行plt.show() 没有绘图,也没有显示错误。感谢任何帮助。

我为 Windows 操作系统安装了带有 Python 3 的 Anaconda。我的 Mac 笔记本电脑正在 Bootcamp 上运行。

【问题讨论】:

  • 你在什么地方运行你的 Python 代码:PyCharm、Spyder、Canopy、Jupyter notebook、iPython、终端?
  • 我在 Spyder 和 Jupyter notebook 中运行原始代码并得到相同的结果。我也在 Spyder 和 Jupyter 中尝试了你的代码。 Spyder 产生类似的结果,但 Jupyter 挂起(新窗口上的绘图没有响应)。

标签: python matplotlib plot anaconda spyder


【解决方案1】:

标签必须使用括号,例如 plt.xlabel("text"),而不是像示例代码中那样分配给带有 = 的字符串。在您的代码中进行更改,保存更改,退出并重新打开 Spyder 或您正在运行的任何解释器,然后再次运行代码。

plt.figure(1)
plt.scatter(pf["age"], pf["friend_count"])
plt.xlabel("age")
plt.ylabel("friends count")
plt.title("Facebook Friends count by Age")
plt.show()

【讨论】:

  • 尝试了您的代码,但仍然无法正常工作。显示的散点图没有标签和标题。与原始问题类似,我怀疑散点图是由于 plt.scatter() 而不是 plt.show() 显示的
  • 谢谢。它现在正在工作。多么菜鸟的错误!干杯
猜你喜欢
  • 1970-01-01
  • 2013-08-25
  • 2021-05-25
  • 2018-11-19
  • 2017-09-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多