Q: gnuplot newhistogram distinct color legend i am creating a histogram type graph and it turns out that an item with a different color appears in the legend
set style data histogram
set style histogram columnstacked
set style fill pattern
set boxwidth 0.75
set xtics ("17 to 19" 0, "20 to 23" 1, "24 to 25" 2, "more than 26" 3)
set grid y
set border 1

set key outside title 'Sex' width -20 

plot newhistogram " " , "gender.dat" u 2:key(1), '' u 3 , '' u 4, '' u 5

my data
# data
dato "17 to 19" "20 to 23" "24 to 25" "more than 26"
"Male" 12 22 20 5
"Female" 14 28 6 6

results


If you observe, the Item "Female" is in another color


A: The program is confused by the extra line in your data file that is not marked as a comment and is also not used as a line of columnheaders.  If you tell it that there is a line of columnheaders it will work properly, even though in this case you are not actually using it that way in the plot.
version 5.2:         set key autotitle columnhead
version 5.4:         set datafile columnhead
