为Matplotlib径向条形图(Python3)中的条形图指定特定颜色

为Matplotlib径向条形图(Python3)中的条形图指定特定颜色,python,matplotlib,colors,bar-chart,Python,Matplotlib,Colors,Bar Chart,我希望在条形图中根据大量的标称和顺序条件为条形图中的条形指定特定的颜色 我的数据如下所示: Dataset Type Dataset Count Image 2 Video 10 Image 12 3D Model 1 Audio 3 首先,我希望按条件分配颜色,如以下逻辑: df['Dataset Type'] == 'Image' then r

我希望在条形图中根据大量的标称和顺序条件为条形图中的条形指定特定的颜色

我的数据如下所示:

Dataset Type        Dataset Count
Image               2
Video               10
Image               12
3D Model            1
Audio               3
首先,我希望按条件分配颜色,如以下逻辑:

df['Dataset Type'] == 'Image' then red
df['Dataset Type'] == 'Video' then blue
df['Dataset Type'] == '3D Model' then green
etc.
类似地,我希望将逻辑应用于数值,例如:

df['Dataset Count'] <= 5 then hatch (stripe)
df['Dataset Count'] => 6 then hatch (star)
它的电流输出:


提前感谢。

本质上,您是在询问如何基于映射将一列字符串映射到另一列字符串
{“Image”:“red”,…}
。请参见Re:字符串列。对于数据集类型,这是正确的,但对于条件图案填充则不是
counts = df['Dataset Count']
labels = df['Dataset'] #the name of the actual datasets I'm examining

iN = len(counts)
arrCnts = np.array(counts)

theta=np.arange(0,2*np.pi,2*np.pi/iN)
width = (2*np.pi)/iN *0.8
bottom = 20

fig = plt.figure(figsize=(30,30))
ax = fig.add_axes([0.1, 0.1, 0.75, 0.75], polar=True)
bars = ax.bar(theta, arrCnts, width=width, bottom=bottom)
plt.axis('off')

rotations = np.rad2deg(theta)
y0,y1 = ax.get_ylim()

for x, bar, rotation, label in zip(theta, bars, rotations, labels):
    offset = (bottom+bar.get_height())/(y1-y0)
    lab = ax.text(0, 0, label, transform=None, 
         ha='center', va='center', size=10)
    renderer = ax.figure.canvas.get_renderer()
    bbox = lab.get_window_extent(renderer=renderer)
    invb = ax.transData.inverted().transform([[0,0],[bbox.width,0] ])
    lab.set_position((x,offset+(invb[1][0]-invb[0][0])/2.*2.7 ) )
    lab.set_transform(ax.get_xaxis_transform())
    lab.set_rotation(rotation)

plt.show()