Home > OS >  Pandas doens't show scatter matrix
Pandas doens't show scatter matrix

Time:11-13

I don't see scatter matrix

I used this code in VSCode:

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)

but nothing happens, it doesn't show scatter matrix. There is no error message in command line.

CodePudding user response:

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()
  • Related