npr*_*oss 7 python plot matplotlib colormap
我想使用反向 Spectral colormap
,
https://matplotlib.org/examples/color/colormaps_reference.html
对于线图。
这适用于十六进制图:
color_map = plt.cm.Spectral_r
image = plt.hexbin(x,y,cmap=color_map)
Run Code Online (Sandbox Code Playgroud)
但是当我这样做的时候
ax1.plot(x,y, cmp=color_map)
Run Code Online (Sandbox Code Playgroud)
这给了我::
AttributeError: 未知属性 cmap
请注意,我只想设置colormap
并让matplotliob
其余的工作;即我不想color=' argument
在 .plot 命令中有一个。
我认为seaborn的color_palette
功能对于这个目的来说非常方便。它可以在with
语句中用于临时设置一个图或一组图的颜色循环。例如:
import matplotlib.pyplot as plt
import numpy as np
import seaborn as sns
with sns.color_palette("Spectral", n_colors=10):
plt.plot(np.random.rand(5, 10))
Run Code Online (Sandbox Code Playgroud)
您可以与任何预定义的matplotlib或seaborn colormap一起使用,或提供自定义颜色序列。
归档时间: |
|
查看次数: |
20090 次 |
最近记录: |