matplotlib:控制饼图字体颜色,线宽 [英] matplotlib: Controlling pie chart font color, line width

查看:362
本文介绍了matplotlib:控制饼图字体颜色,线宽的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用一些简单的matplotlib函数绘制饼图:

I'm using some simple matplotlib functions to draw a pie chart:

f = figure(...)
pie(fracs, explode=explode, ...)

但是,我无法确定如何设置默认字体颜色,线条颜色,字体大小-或将它们传递给pie().怎么做?

However, I couldn't find out how to set a default font color, line color, font size – or pass them to pie(). How is it done?

推荐答案

可以使用rcParams词典调整全局默认颜色,线宽,大小等:

Global default colors, line widths, sizes etc, can be adjusted with the rcParams dictionary:

import matplotlib
matplotlib.rcParams['text.color'] = 'r'
matplotlib.rcParams['lines.linewidth'] = 2

可以在此处

A complete list of params can be found here.

绘制饼图后,您还可以调整线宽:

You could also adjust the line width after you draw your pie chart:

from matplotlib import pyplot as plt
fig = plt.figure(figsize=(8,8))
pieWedgesCollection = plt.pie([10,20,50,20],labels=("one","two","three","four"),colors=("b","g","r","y"))[0] #returns a list of matplotlib.patches.Wedge objects
pieWedgesCollection[0].set_lw(4) #adjust the line width of the first one.

不幸的是,我无法从Pie方法或Wedge对象中找到一种方法来调整饼形图标签的字体颜色或大小.查看axes.py的源代码(matplotlib 99.1上的第4606行),它们是使用Axes.text方法创建的.此方法可以使用color和size参数,但是当前未使用.在不编辑源代码的情况下,您唯一的选择就是如上所述进行全局处理.

Unfortunately, I can not figure out a way to adjust the font color or size of the pie chart labels from the pie method or the Wedge object. Looking in the source of axes.py (lines 4606 on matplotlib 99.1) they are created using the Axes.text method. This method can take a color and size argument but this is not currently used. Without editing the source, your only option may be to do it globally as described above.

这篇关于matplotlib:控制饼图字体颜色,线宽的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆