Python pyplot更改饼图切片字体

Python pyplot更改饼图切片字体,python,matplotlib,Python,Matplotlib,我正在尝试创建一个类似以下内容的基本饼图: 然而,我的一个切片将是黑色的,我想改变字体只为该切片。我环顾四周,但找不到任何指示,只是改变一片 有什么想法吗?你能做的是: import matplotlib.pyplot as plt from matplotlib.gridspec import GridSpec # Some data labels = 'Frogs', 'Hogs', 'Dogs', 'Logs' fracs = [15, 30, 45, 10] colors = 'b

我正在尝试创建一个类似以下内容的基本饼图:

然而,我的一个切片将是黑色的,我想改变字体只为该切片。我环顾四周,但找不到任何指示,只是改变一片

有什么想法吗?

你能做的是:

import matplotlib.pyplot as plt
from matplotlib.gridspec import GridSpec

# Some data

labels = 'Frogs', 'Hogs', 'Dogs', 'Logs'
fracs = [15, 30, 45, 10]
colors = 'black', 'blue', 'green', 'red'
explode = (0, 0.05, 0, 0)

pie_colours = plt.pie(fracs, labels=labels, colors=colors,
                                autopct='%.0f%%',
                                shadow=True,)# radius=0.5)

pie_colours[2][0].set_color('y')
# Make the labels on the small plot easier to read.
for texts in pie_colours[1]:
    texts.set_size('smaller')
for autotexts in pie_colours[2]:
    autotexts.set_size('x-small')

plt.show()

我编辑后得到了它。

谢谢。我试过了,但出现了以下错误:pie_colors[0]。set_color(“y”)AttributeError:“list”对象没有属性“set_color”,但您对
set_size
没有问题。您能用现在的代码编辑您的问题吗?set_size给出了相同的错误。这是我用来创建“pie_colors”的一行:pie_colors=pie(颜色计数[:8],标签=颜色,颜色=颜色,分解=分解,自动扫描=“%1.1f%%”),通常
autotext[x]
应为
matplotlib.text.text类型
import matplotlib.pyplot as plt
from matplotlib.gridspec import GridSpec

# Some data

labels = 'Frogs', 'Hogs', 'Dogs', 'Logs'
fracs = [15, 30, 45, 10]
colors = 'black', 'blue', 'green', 'red'
explode = (0, 0.05, 0, 0)

pie_colours = plt.pie(fracs, labels=labels, colors=colors,
                                autopct='%.0f%%',
                                shadow=True,)# radius=0.5)

pie_colours[2][0].set_color('y')
# Make the labels on the small plot easier to read.
for texts in pie_colours[1]:
    texts.set_size('smaller')
for autotexts in pie_colours[2]:
    autotexts.set_size('x-small')

plt.show()