Pandas doens't show scatter matrix

Question:

I don’t see a scatter matrix if I run the following code in Visual Studio Code:

import numpy as np
import pandas as pd
df = pd.DataFrame(np.random.randn(1000, 4), columns=['A','B','C','D'])
pd.plotting.scatter_matrix(df, alpha=0.2)

There is also no error message in the command line.

Asked By: Turar Khafiz

||

Answers:

you want scatter matrix in question title but you use plot in code. Will you try this?

import numpy as np
import pandas as pd
from pandas.plotting import scatter_matrix

df = pd.DataFrame(np.random.randn(1000, 4), columns=['A','B','C','D'])
scatter_matrix(df, alpha=0.2)

if you still don’t see scatter matrix,
according to @medium-dimensional’s suggestion you have to import pyplot:

import numpy as np
import pandas as pd
from pandas.plotting import scatter_matrix
import matplotlib.pyplot as plt
df = pd.DataFrame(np.random.randn(1000, 4), columns=['A','B','C','D'])
scatter_matrix(df, alpha=0.2)
plt.show()
Answered By: Clegane
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.