How to avoid line color repetition in matplotlib.pyplot?

I am comparing some algorithmic results using matplotlib.pyplot, however it is very difficult to understand what is happening as several lines have the same exact color. Is there any way to avoid this? I don't think pyplot has only seven colors, right?

+6
source share
5 answers

Matplotlib has over seven colors. You can specify your color in many ways (see http://matplotlib.sourceforge.net/api/colors_api.html ).

For example, you can specify the color using the html hexadecimal string:

pyplot.plot(x, y, color='#112233')
+6
source

, , , :

import matplotlib.pyplot as plt
import numpy as np

fig1 = plt.figure()
ax1 = fig1.add_subplot(111)
number_of_plots=10
colormap = plt.cm.nipy_spectral #I suggest to use nipy_spectral, Set1,Paired
ax1.set_color_cycle([colormap(i) for i in np.linspace(0, 1,number_of_plots)])
for i in range(1,number_of_plots+1):
    ax1.plot(np.array([1,5])*i,label=i)

ax1.legend(loc=2)  

nipy_spectral

enter image description here

Set1 enter image description here

+7

Seaborn. , . . :

import seaborn as sns

colors = sns.color_palette("hls", 4)
sns.palplot(colors)
plt.savefig("pal1.png")
colors = sns.color_palette("hls", 8)
sns.palplot(colors)
plt.savefig("pal2.png")
colors = sns.color_palette("Set2", 8)
sns.palplot(colors)
plt.savefig("pal3.png")

:

enter image description here

enter image description here

enter image description here

+2

Python 3 :

colormap = plt.cm.nipy_spectral
colors = [colormap(i) for i in np.linspace(0, 1,number_of_plots)]
ax.set_prop_cycle('color', colors)

:

import seaborn as sns

    colors = sns.color_palette("hls", number_of_plots)
    ax.set_prop_cycle('color', colors)
0

Seaborn . ploting coumns.

import pandas as pd
import seaborn as sns

df = pd.read_csv('file.csv')

ax = df.plot(x, y)
sns.set_palette(sns.color_palette('hls', 12))

, Seaborn .

0
source

All Articles