如何更改 Matplotlib 中的文本颜色?

Ren*_*bex 5 python styles data-visualization matplotlib pandas

如何更改 matplotlib 图形的颜色?现在标题是黑色的,但其他文本是灰色的。我正在使用 Pandas 图创建 Hexbin 图。我已经尝试过了

matplotlib.rcParams.update({'text.color': 'black'})
Run Code Online (Sandbox Code Playgroud)

正如我从http://matplotlib.org/users/customizing.html中了解到的,但它不起作用。

import matplotlib.pyplot as plt
import matplotlib
matplotlib.style.use('ggplot')
font = {'family' : 'normal',
        'weight' : 'bold',
        'size'   : 22}                          
matplotlib.rc('font', **font)

t = pessoas.plot.hexbin(x='qteViagens',y='qteDestUnicos',cmap=plt.cm.jet,gridsize=20,norm=matplotlib.colors.LogNorm(),colorbar=False)
t.set_xlabel('Number of Trips in Period')
t.set_ylabel('Number of Unique Destinations')
t.set_title('Number of Users')
Run Code Online (Sandbox Code Playgroud)

Matplotlib Hexbin 图

Gon*_*ica 1

为了改变轴的颜色,可以这样做

axes.xaxis.label.set_color("yellow")

axes.yaxis.label.set_color("green")
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

或者,可以在使用 创建标签时传递标签的颜色matplotlib.axes.Axes.set_xlabel,例如

ax.set_xlabel('Number of Trips in Period', color='yellow') 
Run Code Online (Sandbox Code Playgroud)