0

I've spent too many hours trying to figure out how to use pre-made colormap or color palette for my plots in Python. How does one change the colormap for his plots? Is there some simple way of doing it?

I did try to use function such as

plt.set_cmap('Set1')

but I'm using it wrong I guess. Here's the code I want the palette to be changed in:

import matplotlib.pyplot as plt
for i in range(10):
    plt.plot([0,1],[i,i])
plt.show()

I made workaround for now, but I would be pleased if someone came up with a real solution.

import matplotlib.pyplot as plt

colors = ["#1f77b4","#ff7f0e","#2ca02c","#f61600","#7834a9",
"#17becf","#684427","#fa5deb","#17becf","#17becf"]

for i in range(10):
    plot.plt([0,1],[i,i], color = colors[i])
plt.show()

The task is simple, change the default color palette to one of these qualitative ones (e.g. 'Set1', 'tab20'): https://matplotlib.org/3.1.1/tutorials/colors/colormaps.html

Killaduu
  • 1
  • 1
  • 2

1 Answers1

1

I don't know if it help but a similar question had been asked here : Question

EDIT : Here is all pre-made colormap :enter image description here

Hugo Chittaro
  • 111
  • 10
  • The problem is I think that scatter plots has the default argument for cmap, if you use plt.plot() it doesn't have that. The data I'm visualizing is connected via lines. I need that every plot has different solid color, but not from the default palette. – Killaduu Jul 26 '19 at 13:14
  • This is a nice list of colour maps, but it does not answer the question how to actually use them. What commands do I have to use to use these predefined colour maps. The link you posted is about how to make your own colour map. But I already don't know how to use the predefined ones. – Ente Fetz Sep 08 '22 at 11:46