0

Because I am new to data analysis with python, I want to improve my skills with tutorials and adjusting working code from others.

At the moment I am working on the fruit_data_with_colors data set, and want to understand the python code, available at:

https://github.com/susanli2016/Machine-Learning-with-Python/blob/master/Solving%20A%20Simple%20Classification%20Problem%20with%20Python.ipynb

One of the examples at the beginning shows a scatter matrix of the different numeric input variables (height, width, mass, color). With the mentioned code, the colors in the plotted images are purple, brown, yellow and black. I would like to change this to more appealing colors (e.g. red, blue, green, black)

I looked at the documentation of matplotlib and think that I should adjust the "c = y" part of my code. https://matplotlib.org/3.1.1/api/_as_gen/matplotlib.pyplot.scatter.html

Trying "c = ['blue']" worked well, but if I add another color in the form of "c = ['blue', 'red']" an error occures:

ValueError: 'c' argument has 2 elements, which is not acceptable for use with 'x' with size 59, 'y' with size 59.

X = fruits[feature_names] y = fruits['fruit_label'] from matplotlib import cm cmap = cm.get_cmap('gnuplot') scatter = pd.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')``` 

1 Answer 1

1

I think the easiest way to achieve what you want is to change the colormap, just edit:

cmap = cm.get_cmap('new_color_map') 

with a more appealing colormap. You can check the full list here. In addition also seaborn library provides some nice colormaps. In seaborn you can produce nice scatter matrix plots using the pairplot function!

Sign up to request clarification or add additional context in comments.

1 Comment

In particular you can use cmap = matplotlib.colors.ListedColormap(["red", "blue", "green", "black"]) to get the colors asked for in the question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.