- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
编辑:我无法共享实际数据,但这里有一个示例数据框
df = pd.DataFrame({'education_grouped': ['None', 'Primary', 'Secondary',
'Post-secondary', 'Bachelor', 'Master', 'Doctoral', 'None', 'Primary',
'Secondary', 'Post-secondary', 'Bachelor', 'Master', 'Doctoral', 'None',
'Primary', 'Secondary', 'Post-secondary', 'Bachelor', 'Master', 'Doctoral']})
我正在使用以下代码制作 donut 饼图
sizes = df['education_grouped'].value_counts().sort_index() / df['education_grouped'].value_counts().sum() * 100
educ_order2 = ['None', 'Primary', 'Secondary', 'Post-secondary', 'Bachelor', 'Master', 'Doctoral']
cmap = plt.get_cmap("Set2")
colors = cmap(np.array([1, 2, 3, 4, 5, 6, 7]))
explode = (0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05)
fig1, ax1 = plt.subplots()
ax1.pie(sizes,
labels=educ_order2,
startangle=90,
explode=explode,
colors=colors,
counterclock=False,
shadow=False,
wedgeprops={'edgecolor': 'white'},
textprops={'fontsize': 7},
pctdistance=0.8,
autopct='%1.1f%%')
centre_circle = plt.Circle((0,0),0.70,fc='white')
fig = plt.gcf()
fig.gca().add_artist(centre_circle)
ax1.axis('equal')
plt.title('Educational attainment', fontsize=16, pad=20)
plt.tight_layout()
但是,我对它不再显示为圆圈这一事实感到困扰。见下文,似乎有些部分比其他部分移动得更远。这对我来说似乎很奇怪,因为我以相同的数量 explode 了所有切片。有没有人对这里发生的事情有任何暗示?
最佳答案
最好关闭 explode 参数。将其设为零可消除不等式。相比之下,您可能想要适应 radius
sizes = df['education_grouped'].value_counts().sort_index() / df['education_grouped'].value_counts().sum() * 100
educ_order2 = ['None', 'Primary', 'Secondary', 'Post-secondary', 'Bachelor', 'Master', 'Doctoral']
cmap = plt.get_cmap("Set2")
colors = cmap(np.array([1, 2, 3, 4, 5, 6, 7]))
fig1, ax1 = plt.subplots(figsize=(8,12))
ax1.pie(sizes,
labels=educ_order2,
radius=1,
explode=[0, 0, 0, 0, 0, 0, 0],
startangle=90,
colors=colors,
counterclock=False,
shadow=False,
wedgeprops={'edgecolor': 'white', 'linewidth': 4},
textprops={'fontsize': 7},
pctdistance=0.85,
autopct='%1.1f%%')
centre_circle = plt.Circle((0,0),0.70,fc='white')
fig = plt.gcf()
fig.gca().add_artist(centre_circle)
ax1.axis('equal')
plt.title('Educational attainment', fontsize=16, pad=20)
plt.tight_layout()
如果你把其中一个放得高一点,例如。
explode=[0.2, 0, 0, 0, 0, 0, 0]
,它为其中一个馅饼提供了很好的特殊效果。该参数可能旨在突出显示一个或几个分数。
关于python - Matplotlib 饼图 explode 不圆,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65074529/
一个很简单的问题。我有一个要在 JBoss 上运行的 .war(~40MB) 文件。部署的最佳实践是什么:war 文件应该以分解格式部署吗?还是不行? 我问是因为如果它爆炸了,那么我可以选择随时更新我
转到 http://hartford.uconn.edu/scholarships/单击任何名称,然后单击“关闭”按钮,这将显示在“展开”时字体从默认的“Trebuchet MS/Trebuchet”
我正在将Json数据插入Hive。这是格式- A1 Array > dim2 array >
我正在制作一个可以在本地服务器上运行的 java 程序。 服务器使用 PHP 从客户端接收请求。 现在我在本地服务器上有文件“temp.txt”。 Java 程序应该逐行打开文件,每行都应该用
Crashlytics 报告了多次崩溃并显示以下消息: function signature specialization 这个异常首先意味着什么? 这是我的代码,在闭包内的“return resu
array ( [0] => 3 / 4 Bananas [1] => 1 / 7 Apples [2] => 3 / 3 Kiwis ) 可以说,遍历此列表,并
我正在优化我的网站。在本地测试了页面,一切正常。当我上传它并实时访问它时,它会突然抛出一个解析错误……但它在本地完美运行,就像我说的那样。 Parse error: syntax error, un
这个问题在这里已经有了答案: How to split a string by multiple delimiters in PHP? (4 个回答) 关闭 8 个月前。 我有一个问题,我有一个字符串
我希望能够在 explode 后得到剩余的字符串。 $string = "First Middle Last"; $d = explode(" ", $string); print_r($d); Ou
我正在尝试从字符串中获取一个简单的数组。 Ej。 [位置] => ???? [标题] => ??? [音调] => ??? [缩放] => ??? 但由于某种原因,我收到以下错误: Notice: U
如何在分隔符“[”之间分解字符串,但我希望分隔符不会丢失 例如,我有这样的字符串 $str = "i want to show you my youtube channel : [youtube id
请帮我解决这个 explode() 函数问题。对于第三种情况,我得到了意想不到的结果,解释是什么? 编辑: $page_string 值实际上来自数据库。这次我使用 var_dump 而不是 echo
我正在制作一个电子商务网站。我在测试时遇到了以下问题: 从管理面板更新订单状态(处理中、发货、已完成和已取消)不适用于 1 种产品。 当从数据库中检索值时,Explode 会删除最后一个字符。 如果订
好吧,首先,如果之前有人问过这个问题,我很抱歉,我在过去的 12 个小时里筛选了数百个论坛主题,但还没有找到能准确回答这个问题的主题,所以这里开始吧。 我有一个我构建的页面,它有一个用户列表,当用户登
我有一个表,其中有一个包含以下记录的字段: 1,2,3,4,5,6 我想请教以下两件事: 1)如何在另一个表中创建外键?规则是:对于字段“field_name”中以逗号分隔的任何值,必须是 other
我只是对如何分解字符串以单独插入数据库感到困惑。 我的代码: $mymotives = "Entrega de Documentos, Orientacion, Username y Password
我们有这个字符串:“Il Responsabile della Sicurezza nelle gallerie – 1° PARTE”,我们想要得到它的两个部分: Il Responsabile d
我有一个函数 symbol_scan(integer) 返回一个包含三列的表:schema, table, count。 我可以像这样对其执行选择查询: > SELECT name, symbol_s
嗨,实际上,当我执行代码时,我得到一个输出,它将被吐出在 echo 语句中,但如果我将 echo 放入文本区域,我只能从数据库中获取字符串的最后一个值 $sql = mysqli_query(
我正在尝试构建一个 PHP 代码来检测类似 Twitter 的提及,但我不是链接到 @username,而是定位用户的 ID 并引用它。 function get_user_id_from_usern
我是一名优秀的程序员,十分优秀!