python怎么在饼图上加数据
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python怎么在饼图上加数据相关的知识,希望对你有一定的参考价值。
参考技术A matplotlib包的pie函数可以绘制饼形图import matplotlib.pyplot as plt
x = [0.2,0.3,0.5]
labels = ['China', 'Japan', 'America']
plt.pie(x, labels=labels, labeldistance=0.5)本回答被提问者采纳
如何仅在钻取饼上显示数据标签?
嘿家伙我已经对饼图进行了条形图钻取,因此其中有一个名为“plotOptions”和“datalabels”的东西,数据标签显示每个条形/切片的值,但我希望数据标签只显示在饼图上图表而不是条形图当前它在条形图上显示如下:
正如您可以看到值“264.50%”和“164.50”,我不想显示该值。但我不能从代码中删除数据标签,否则它也不会在我的饼图上显示我。
那我怎么能只从条形图中删除它?我的代码如下:
<script>
Highcharts.chart('container', {
chart: {
type: 'column'
},
title: {
text: 'Chart'
},
xAxis: {
type: 'category'
},
yAxis: {
title: {
text: ''
}
},
legend: {
enabled: false
},
plotOptions: {
series: {
borderWidth: 0,
dataLabels: {
enabled: true,
formatter: function () {
var mychart = $('#container').highcharts();
var mytotal = 0;
for (i = 0; i < mychart.series.length; i++) {
if (mychart.series[i].visible) {
mytotal = {!! $countTotalRecord['low confidence'] !!} + {!! $countTotalRecord['no answer'] !!} + {!! $countTotalRecord['missing intent'] !!} + {!! $countTotalRecord['webhook fail'] !!};
}
}
var pcnt = (this.y / mytotal) * 100;
return Highcharts.numberFormat(pcnt) + '%';
}
}
}
},
tooltip: {
// headerFormat: '<span style="font-size:11px">{series.name}</span><br>',
pointFormat: '{point.name}: <b>{point.y}</b>'
},
credits:{
enabled: false
},
series: [{
name: 'front',
colorByPoint: true,
data: [{
name: 'Total',
y: {!! $countTotalRecord['total'] !!},
drilldown: 'total'
}, {
name: 'Match',
y: {!! $countTotalRecord['match'] !!},
drilldown: 'match'
}]
}],
drilldown: {
series: [{
name: 'total',
id: 'total',
type:'pie',
data: [
[
'Low Confidence',
{!! $countTotalRecord['low confidence'] !!}
],
[
'No Answer',
{!! $countTotalRecord['no answer'] !!}
],
[
'Missing Intent',
{!! $countTotalRecord['missing intent'] !!}
],
[
'Webhook Fail',
{!! $countTotalRecord['webhook fail'] !!}
]
]
}]
}
});
</script>
答案
您可以在任何您不想看到数据标签的关卡系列中传递dataLables
enable false
series: [{
name: 'Brands',
colorByPoint: true,
data: [{....}],
dataLabels: {
enabled: false,
}
}],
以上是关于python怎么在饼图上加数据的主要内容,如果未能解决你的问题,请参考以下文章