Reputation: 939
I'm trying to run pd.scatter_matrix()
function in Jupyter Notebook with my code below:
import matplotlib.pyplot as plt
import pandas as pd
# Load some data
iris = datasets.load_iris()
iris_df = pd.DataFrame(iris['data'], columns=iris['feature_names'])
iris_df['species'] = iris['target']
pd.scatter_matrix(iris_df, alpha=0.2, figsize=(10, 10))
plt.show()
But I'm getting
AttributeError: module 'pandas' has no attribute 'scatter_matrix'
.
Even after executing conda update pandas
and conda update matplotlib
commands in Terminal, this is still occurring.
I executed pd.__version__
command to check my pandas version and it's '0.24.2'
. What could be the problem?
Upvotes: 33
Views: 43760
Reputation: 1373
In our case we were executing below code "axs = pd.scatter_matrix(sampled_data, figsize=(10, 10))
"
so the error clearly says scatter_matrix is not available in pandas
Solution: A bit of google and we found scatter_matrix is available in pandas.plotting
So correct code is "axs = pd.plotting.scatter_matrix(sampled_data, figsize=(10, 10)) "
Upvotes: 1
Reputation: 31
Use:
from pandas.plotting import scatter_matrix
The code becomes:
import matplotlib.pyplot as plt
from pandas.plotting import scatter_matrix
iris = datasets.load_iris()
iris_df = pd.DataFrame(iris['data'], columns=iris['feature_names'])
iris_df['species'] = iris['target']
scatter_matrix(iris_df, alpha=0.2, figsize=(10, 10))
plt.show()
Upvotes: 2
Reputation: 21
I used
from pandas.plotting import scatter_matrix
and called scatter_matrix
directly worked like charm.
Upvotes: 0
Reputation: 51
Using
from pandas.plotting._misc import scatter_matrix
don't use pd.scatter_matrix
or pandas.scatter_matrix
you can directly call scatter_matrix
e.g.
cmap = cm.get_cmap('gnuplot')
scatter = scatter_matrix(X, c = y, marker = 'o', s=40, hist_kwds={'bins':15},
figsize=(9,9), cmap = cmap)
plt.suptitle('Scatter-matrix for each input variable')
plt.savefig('fruits_scatter_matrix')
plt.show()
Upvotes: 5
Reputation: 388
Another option is keeping only pandas import and rewriting the command scatter_matrix
, like in the example below:
import pandas as pd
pd.plotting.scatter_matrix(iris_df, alpha=0.2, figsize=(10, 10))
Upvotes: 22
Reputation: 862911
This method is under pandas.plotting
- docs and pandas.plotting.scatter_matrix
:
from pandas.plotting import scatter_matrix
scatter_matrix(iris_df, alpha=0.2, figsize=(10, 10))
Upvotes: 65