Search code examples
pythonpandasplotscatter-matrix

What is required in my code to make my scatter_matrix appear?


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!


Solution

  • 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