seaborn循环通过颜色与matplotlib分散

amn*_*n41 21 python matplotlib seaborn

在进行散点图时,如何获得seaborn颜色?

import matplotlib.pyplot as plt
import seaborn as sns
ax=fig.add_subplot(111)
for f in files:
    ax.scatter(args) # all datasets end up same colour
    #plt.plot(args) #  cycles through palette correctly
Run Code Online (Sandbox Code Playgroud)

Car*_*ten 42

你必须告诉matplotlib使用哪种颜色.例如,使用seaborn的默认调色板:

import matplotlib.pyplot as plt
import seaborn as sns
import itertools
ax=fig.add_subplot(111)

palette = itertools.cycle(sns.color_palette())

for f in files:
    ax.scatter(args, color=next(palette))
Run Code Online (Sandbox Code Playgroud)

itertools.cycle确保我们不会跑出来的颜色,并使用最后一个后再次以第一个开始.

  • 更好地使用 `sns.color_palette(None, len(files)` https://seaborn.pydata.org/tutorial/color_palettes.html (2认同)