简体   繁体   中英

Add values on top of bars in barplot Julia

I have the following barplot in Julia Plots:

using DataFrames
using Plots

df = DataFrame(group = ["A", "B"], 
               value = [10, 9])

bar(df[!, "group"], df[!, "value"], legend = :none)

Output:

在此处输入图像描述

I would like to show the values of each bar on top of each bar. So in this example, it should show the values 10 for bar A and 9 for bar B. Is there an automatic way for this or should you annotate the values in Julia Plots ?

I found the argument texts which can show the value on top on the bars like this:

bar(df[!, "group"], df[!, "value"], legend = :none, texts = df[!, "value"])

Output:

在此处输入图像描述

As you can see it shows the values, but it isn't nicely aligned.

An approach using annotate .

julia> using DataFrames
julia> using Plots

julia> bar(df.group, df.value, legend = :none)

julia> annotate!(df.group, df.value, df.value, :bottom)

条形图上方带有文本注释的条形图

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM