英文:
What is required in my code to make my scatter_matrix appear?
问题
我正在尝试使用pandas.plotting.scatter_matrix绘制我的数据点,但是每当我输入代码时,什么都不显示,所以我不确定我在代码中漏掉了什么。
import pandas as pd
import numpy as np
# 使此示例可重现
np.random.seed(0)
# 创建DataFrame
df = pd.DataFrame({'points': np.random.randn(1000),
'assists': np.random.randn(1000),
'rebounds': np.random.randn(1000)})
# 查看DataFrame的前五行
df.head()
pd.plotting.scatter_matrix(df)
我从网上复制了这段代码,以确保问题不是出在我的代码上,但它仍然不起作用,只显示“进程已退出,退出代码为0”,当我运行它时没有显示任何内容。
我在pycharm上运行程序,不确定是否有什么变化。提前感谢!
英文:
I'm just getting into some basic machine learning and I'm trying to graph out my data points with pandas.plotting.scatter_matrix. However, whenever I put in the code for it, nothing shows up so I'm not sure what I'm missing in my code.
import pandas as pd
import numpy as np
#make this example reproducible
np.random.seed(0)
#create DataFrame
df = pd.DataFrame({'points': np.random.randn(1000),
'assists': np.random.randn(1000),
'rebounds': np.random.randn(1000)})
#view first five rows of DataFrame
df.head()
pd.plotting.scatter_matrix(df)
I copied this code from online to make sure it wasn't just a problem with my code, and it still doesn't work and all it says is "Process finished with exit code 0" and nothing is displayed on when I run it.
I am running the program on pycharm, not sure if that changes anything. Thanks in advance!
答案1
得分: 0
你已经创建了一个图表,但尚未显示它:
plt.show()
当然,在顶部导入matplotlib.pyplot:
import matplotlib.pyplot as plt
英文:
You have created a plot but not displayed it yet:
plt.show()
And of course import matplotlib.pyplot at top:
import matplotlib.pyplot as plt
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论