Search code examples
gnuplot

Turn Off Select Titles in gnuplot Histogram Legend


I want to plot data in a histogram where there are two approaches being compared with 2 different experiments and various settings for each experiment. The settings are the same across different approaches / experiments. Below is my script for doing this, which is a variation of the example found here.

reset
clear

set border 3 front lt black linewidth 1.000 dashtype solid
set boxwidth 0.95 absolute
set style fill solid 1.00
set grid noxtics nomxtics ytics nomytics noztics nomztics nortics nomrtics \
 nox2tics nomx2tics noy2tics nomy2tics nocbtics nomcbtics
set style histogram clustered gap 1 title textcolor lt -1 offset character 2, 0.25
set style data histograms
set xtics border in scale 0,0 nomirror rotate by -45  autojustify
set xtics  norangelimit  font ",8"
set xtics   ()
set ytics border in scale 0,0 mirror norotate  autojustify
set ytics  norangelimit autofreq  font ",8"
set xlabel  offset character 0, -2, 0 font "" textcolor lt -1 norotate
set xrange [ * : * ] noreverse writeback
set ylabel "Percent Success" 
set yrange [ 0 : 100 ] noreverse writeback

plot newhistogram "Approach 1", 'aprch1.dat' using "Setting A":xtic(1) t col lc 1 fs pattern 1, '' u "Setting B" t col lc 2 fs pattern 5, '' u "Setting C" t col lc 3 fs pattern 7, newhistogram "Approach 2", 'aprch2.dat' using "Setting A":xtic(1) t col lc 1 fs pattern 1, '' u "Setting B" t col lc 2 fs pattern 5, '' u "Setting C" t col lc 3 fs pattern 7

Here is what aprch1.dat looks like. aprch2.dat is similar.

Title   "Setting A" "Setting B" "Setting C"
"Experiment 1 " 84.32451898 73.54666118 79.07579357
"Experiment 2 " 84.25763967 45.88435024 42.17414819

Here is the resulting graph:

enter image description here

However, the legend is redundant. How do I remove the duplicates in the legend?

I have tried using notitle and set key noautotitle, as described in this question, but I'm getting nasty errors and not the desired result. I will admit that I do not totally understand all of the commands in the script. Am I setting something that doesn't allow me to use notitle or is there a better approach to get the desired result?


Solution

  • You should use notitle only int the second part of the plot command:

    plot newhistogram "Approach 1", 'aprch1.dat' using "Setting A":xtic(1) t col lc 1 fs pattern 1, '' u "Setting B" t col lc 2 fs pattern 5, '' u "Setting C" t col lc 3 fs pattern 7, newhistogram "Approach 2", 'aprch2.dat' using "Setting A":xtic(1) notitle lc 1 fs pattern 1, '' u "Setting B" notitle lc 2 fs pattern 5, '' u "Setting C"  notitle fs pattern 7
    

    Result