【发布时间】:2021-12-11 15:25:52
【问题描述】:
我有这个代码:
import matplotlib.pyplot as plt
import pandas as pd
df = pd.DataFrame({
'Name': ['A', 'B', 'C', 'D', 'E', 'F'],
'Value': [10, 2, 23, 87, 12, 65]
})
circles = circlify.circlify(
df['Value'].tolist(),
show_enclosure=False,
target_enclosure=circlify.Circle(x=0, y=0, r=1)
)
# Create just a figure and only one subplot
fig, ax = plt.subplots(figsize=(10,10))
# Title
ax.set_title('Basic circular packing')
# Remove axes
ax.axis('off')
# Find axis boundaries
lim = max(
max(
abs(circle.x) + circle.r,
abs(circle.y) + circle.r,
)
for circle in circles
)
plt.xlim(-lim, lim)
plt.ylim(-lim, lim)
# list of labels
labels = df['Name']
# print circles
for circle, label in zip(circles, labels):
x, y, r = circle
ax.add_patch(plt.Circle((x, y), r, alpha=0.2, linewidth=2,color='#e6d4ff'))
plt.annotate(
label,
(x,y ) ,
va='center',
ha='center',
size=12
)
它产生这个输出:
我只想更改其中一个圆圈的颜色(例如,最大的圆圈)。
我尝试从以下位置更改颜色:
color='#e6d4ff'
例如,颜色列表:
color=['#e6d4ff','#e6d4ff','#e6d4ff','#e6d4ff','#e6d4ff','#ffc4c4']
出现错误:
RGBA sequence should have length 3 or 4
我猜错误是说如果我提供一个列表,那么该列表应该只是 RGB 尺寸。
有人能告诉我吗? (我在 python 图形库中看不到它,例如 [here][2] 或 circlify 文档 here 但也许我错过了?)
【问题讨论】: