【问题标题】:How to change text color in Matplotlib?如何在 Matplotlib 中更改文本颜色?
【发布时间】:2016-11-24 08:15:06
【问题描述】:

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

matplotlib.rcParams.update({'text.color': 'black'})

正如我从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')

Matplotlib Hexbin graph

【问题讨论】:

  • 你可以试试ax.set_xlabel("Number of Trips in Period",color = 'green')
  • @HanZhengzu 谢谢,成功了!

标签: python pandas matplotlib styles data-visualization


【解决方案1】:

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

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

axes.yaxis.label.set_color("green")

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

ax.set_xlabel('Number of Trips in Period', color='yellow') 

【讨论】:

    猜你喜欢
    • 2021-01-07
    • 2020-04-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-02
    • 2012-03-28
    • 1970-01-01
    • 2016-09-06
    相关资源
    最近更新 更多