Skip to main content
 首页 » 编程设计

python之自定义 matplotlib 的配色方案

2025年05月04日9zhoujg

我正在关注 Sane color scheme for Matplotlib ,却发现我的着色是still the same作为the default color scheme .有什么问题吗?

我正在关注 Customizing plots with style sheets ,并在我的代码顶部使用这些:

import matplotlib.pyplot as plt 
plt.style.use('ggplot') 

是这个原因吗?或者是其他东西?

披露,

The default color scheme in matplotlib is pretty ugly. Die-hard matlab/matplotlib fans may stand by their color scheme to the end, but it’s undeniable that Tableau’s default color scheme is orders of magnitude better than matplotlib’s.

更新: 显示我将有效的 matplotlibrc 文件放在正确的位置(已解释 here ):

D:\>python 
Python 3.5.0 |Anaconda 2.4.0 (64-bit)| (default, Dec  1 2015, 11:46:22) [MSC v.1 
900 64 bit (AMD64)] on win32 
>>> import matplotlib 
>>> matplotlib.matplotlib_fname() 
'D:\\Programs\\Anaconda3\\lib\\site-packages\\matplotlib\\mpl-data\\matplotlibrc 
' 
D:\>dir D:\Programs\Anaconda3\libs\site-packages\matplotlib\mpl-data\matplotlibrc 
 Volume in drive D is New Volume 
 
 Directory of D:\Programs\Anaconda3\libs\site-packages\matplotlib\mpl-data 
 
12/18/2015  05:34 PM            25,738 matplotlibrc 
               1 File(s)         25,738 bytes 

请您参考如下方法:

从 matplotlib 1.5 开始,您可以在一组预定义样式(包括 ggplot)中进行选择。

如果你想创建your own stylesheet你只需要放置一个有效的 matplotlibrc 在某处归档并使用

import matplotlib.pyplot as plt 
plt.style.set("/path/to/your/file.mplstyle") 

然后您可以使用自己的风格。