gnuplot - 상단에 값이 있는 다양한 색상의 히스토그램 막대

gnuplot - 상단에 값이 있는 다양한 색상의 히스토그램 막대

다음 데이터 파일( )이 있습니다 TotalDurationBarPlot.dat.

Indexed list 934
Tree list 3692
Array list 12274
Linked list 48188

내가 달성하고 싶은 것은 4개의 막대가 있는 히스토그램입니다.색인 목록, 하나는트리 목록, 하나는배열 목록, 하나는연결리스트. 내 요구 사항은 다음과 같습니다

  1. 각 바에는 고유한 색상이 있으며,
  2. 각 막대의 상단에는 막대의 높이를 나타내는 숫자가 있습니다. (예를 들어 위의트리 목록, 가지다3692.)
  3. 연한 회색 배경에 오른쪽 상단에 얇은 검정색 범례 테두리가 있는 범례가 있으면 좋을 것 같습니다.

나의 현재 시도

현재 내 데이터 파일은 다음과 같습니다.

# ILL TL AL LL
934 3692 12274 48188

...내 gnuplot 스크립트는 다음과 같습니다:

set title font "Monospaced,13" 'Total duration'
set grid
set key right top
set style data histograms
set style histogram cluster gap 2
set style fill solid border 2
set xtics format ""
set grid ytics
set ylabel "Milliseconds"
set yrange [0:70000]
# set boxwidth 0.5 relative
# set label "Array list\n134908 ms" at graph 0.145,0.9

ArrayListColor   = "#491d75";
IndexedListColor = "#b32929";
LinkedListColor  = "#d49435";
TreeListColor    = "#12520b";

plot 'TotalDurationBarPlot.dat' using 1 title "Indexed list" linecolor rgb IndexedListColor, '' using 2 title "Tree list" linecolor rgb TreeListColor, '' using 3 title "Array list" linecolor rgb ArrayListColor, '' using 4 title "Linked list" linecolor rgb LinkedListColor, '' u 0:1:1 with labels offset -6.0,-100.0 title ""

set terminal png size 650,350 enhanced font "Monospaced,13"
set output 'TotalDuration.png'
replot
exit

그것은 다음을 생산합니다 :

목록 비교

편집 1

gnuplot답변에 제공된 코드@meuh다음 플롯을 생성합니다.

나쁜 바

답변1

나는 stackoverflow에서 얻은 몇 가지 팁을 따랐으며 아직 자신만의 솔루션이 없다면 원본 여러 줄 데이터 파일을 사용하여 충분히 가까운 근사치를 얻었습니다.

set terminal png size 650,350 enhanced font "Monospaced,13"
set output 'TotalDuration.png'
set style fill solid border 2
set key noautotitle
set key box opaque fillcolor "0x7faaaaaa"
set grid x,y
set boxwidth 0.8 relative
set ylabel "Milliseconds"
set yrange [0:90000]

Array   = 0x491d75
Indexed = 0xb32929
Linked  = 0xd49435
Tree    = 0x12520b

list=""
plot 'TotalDurationBarPlot.dat' \
    u 0:3:(value(strcol(1))):xtic(1)   with boxes lc rgb var, \
 '' u 0:3:3:(list=list." ".stringcolumn(1)) with labels offset 0,0.7, \
 for [i=1:4] '' u (NaN):(NaN):(value(word(list,i))) with boxes lc rgb var title word(list,i)

중요한 "fillcolor" 옵션을 얻으려면 gnuplot 6.1에 의존해야 했지만 이 옵션도 5.4에 있어야 하고 제공할 필요가 없었습니다. 여기서 사용되는 주요 기능은 열 1 텍스트("Indexed", "Tree" 등)를 문자열 변수에 저장한 list다음 word(list,i)제목의 단어를 추출하는 데 사용됩니다. for 루프는 파일을 읽지만 모든 데이터가 유효하지 않기 때문에 아무것도 그리지 않습니다 NaN.

색상은 데이터의 열 1과 동일한 이름을 가진 4개의 변수로 설정됩니다. get 열 1을 문자열로 사용한 strcol(1)다음 함수를 사용하여 value()해당 이름의 변수 값을 가져올 수 있습니다. 에서 사용하는 정수입니다 lc rgb var. 루프에서도 마찬가지 지만 여기서는 수집된 이름에서 for이름을 가져옵니다.list

음모

변경하려는 출력의 모든 측면에 대해 stackoverflow에 질문을 게시하여 원하는 답변을 계속해서 얻을 것을 제안합니다.

관련 정보