简体   繁体   English

matplotlib不显示plot()

[英]matplotlib does not show plot()

I tried running plt.show() but no plot is shown. 我尝试运行plt.show(),但未显示任何图。 I had tried lots of solutions from stackoverflow including setting matplotlib backend to Qt4Agg, switching to other backends (ie TkAgg, Agg) and reinstalling matplotlib package but still not solving the issue. 我已经尝试了很多来自stackoverflow的解决方案,包括将matplotlib后端设置为Qt4Agg,切换到其他后端(即TkAgg,Agg)并重新安装matplotlib程序包,但仍然不能解决问题。 Some solutions that I had tried but not working are: 我尝试过但不起作用的一些解决方案是:

matplotlib does not show my drawings although I call pyplot.show() 尽管我调用pyplot.show(),但matplotlib不会显示我的绘图

Matplotlib.Pyplot does not show output; Matplotlib.Pyplot不显示输出; No Error 没错

Why matplotlib does not plot? 为什么matplotlib不作图?

Matplotlib does not show labels or numbers Matplotlib不显示标签或数字

Below is the code that I tried to run: 以下是我尝试运行的代码:

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

When plt.scatter(pf["age"], pf["friend_count"]) code was run, a scatter plot was shown but with no labels and title. 运行plt.scatter(pf["age"], pf["friend_count"])代码时,显示了一个散点图,但没有标签和标题。 Running plt.show() did not plot and no error was shown. 运行plt.show()不会绘图,也不会显示错误。 Appreciate any help. 感谢任何帮助。

I installed Anaconda with Python 3 for Windows OS. 我在Windows OS的Python 3中安装了Anaconda。 My Mac laptop is running on Bootcamp. 我的Mac笔记本电脑正在Bootcamp上运行。

The labels must use parentheses such as plt.xlabel("text") , not assigned to a string with = like you have in your example code. 标签必须使用括号,例如plt.xlabel("text") ,而不是像示例代码中那样使用=分配给字符串。 Make the changes in your code, save the changes, quit and reopen Spyder or whatever interpreter you are running, then run the code again. 在代码中进行更改,保存更改,退出并重新打开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()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM