You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

plot-likert图表小数值类别数据标签不显示问题解决咨询

解决plot-likert小数值数据标签不显示的问题

问题描述

使用plot-likert绘制李克特量表统计图时,数值较小的类别(如示例中Strongly disagree的3.0)无法显示数据标签,但将数值调大(如15)后标签可正常显示,需要确保所有类别都能显示对应的数据标签。

解决方法

plot-likert的plot_counts函数默认会隐藏高度低于阈值的标签,只需显式设置bar_label_min_height=0参数,即可强制显示所有数值的标签:

修改后的完整代码

!pip install plot_likert

import plot_likert
import pandas as pd
import matplotlib.pyplot as plt

precomputed_counts2 = pd.DataFrame(
    {'Strongly disagree': {'Q1': 3.0},
     'Disagree': {'Q1': 9.0},
     'Neither agree nor disagree': {'Q1': 13.0},
     'Agree': {'Q1': 69.0},
     'Strongly agree': {'Q1': 31.0}}
)

# 添加bar_label_min_height=0参数强制显示所有标签
ax = plot_likert.plot_counts(
    precomputed_counts2, 
    plot_likert.scales.agree,
    colors=plot_likert.colors.likert6,
    bar_labels_color="black",
    bar_labels="count",
    bar_label_min_height=0  # 关键参数,设置为0显示所有标签
);
ax.figure.set_size_inches(12, 2)
ax.xaxis.set_label_text('Difficulty Level of Questions');

原理说明

bar_label_min_height是plot-likert控制标签显示的阈值参数,默认值大于0,当条形高度(即数值)低于该阈值时,标签会被自动隐藏。将其设置为0后,所有非零数值的标签都会强制显示,解决小数值标签不显示的问题。

内容的提问来源于stack exchange,提问作者RaisingPhDStar

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.14 10:24:51