0

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!

  • In PyCharm, plots are displayed in the SciView panel under the Plots tab. Look for the scientific mode. – Corralien Jun 15 '23 at 22:41

1 Answers1

0

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

Glogg
  • 28
  • 5
  • All the examples that I've seen so far have the scatter_matrix appear without the show(). But if I was to use the .show() could you show me the code to use for it? ``` plt = pd.plotting.scatter_matrix(df) plt.show() ``` I tried this and it says that the module "pandas" does not have the attribute "show" – BigBrain Productions Jun 15 '23 at 22:35
  • No just this alone as its own line of code. – Glogg Jun 15 '23 at 22:45
  • There's isn't a variable that is called "plt" and I get an error that says "Unresolved reference", so I'm not sure how plt.show() would work on its own. Also, I tried this in jupyter notebook and it displays properly with matplotlib imported, however, still nothing shows up in pycharm, so I'm not exactly sure what's going on here. – BigBrain Productions Jun 15 '23 at 22:55
  • Jupyter notebook will show plots automatically, yes. You have a comment on your post that seems to answer specifically for PyCharm so that is likely to work. – Glogg Jun 15 '23 at 23:00
  • Dis you import matplotlib? – Glogg Jun 15 '23 at 23:03
  • import matplotlib.pyplot as plt – Glogg Jun 15 '23 at 23:03
  • Thank you very much it worked out for me! – BigBrain Productions Jun 15 '23 at 23:12