gnuplotboxploteps

Grayscale gnuplot with grouped boxplots


I need to create grouped boxplots, ideally using gnuplot exactly as shown in this answer. However, I need a grayscale plot. Moreover, the output has to be an encapsulated Postscript (EPS) file. When adding these two lines

set terminal postscript eps enhanced 24
set output "fruit_prices.eps"

I get the following plot (I converted the EPS file to a PNG file because StackOverflow doesn't accept EPS files):

Grayscale grouped boxplot example

For some reason, all nine boxes have a different line style. I need the first box for Company A, B, and C to have the same style, and the same for the second and third box (matching the coloring in the original example).

How can that be achieved?


Solution

  • The default option for terminal postscript eps is monochrome and apparently you get only one grey fill color but differently dashed lines.

    Without knowing details, you apparently have to set the option color and define your linetypes explicitly and use it in the plot command via lt COL.

    Script: (with the data from here)

    ### grouped boxplots
    reset session
    set terminal postscript eps color enhanced 24
    set output "SO77584267.eps"
    
    set linetype 1 lc rgb 0xcccccc dt 1
    set linetype 2 lc rgb 0x777777 dt 1
    set linetype 3 lc rgb 0x000000 dt 1
    
    FILES     = 'A B C'
    File(n)   = sprintf("Company %s.dat",word(FILES,n))
    myXtic(n) = sprintf("Company %s",word(FILES,n))
    
    set xlabel "Fruit prices"
    set ylabel "Price"
    set yrange [0:5]
    set grid y
    
    set key noautotitle
    set style fill solid 0.3
    
    N    = words(FILES)    # number of files
    COLS = 3               # number of columns in file
    PosX = 0               # x-position of boxplot
    
    plot for [n=1:N] for [COL=1:COLS] PosX=PosX+1 File(n) u (PosX):COL w boxplot lt COL, \
         for [COL=1:COLS] File(1) u (NaN):COL w boxes lt COL ti columnhead, \
         for [n=1:N] File(1) u ((n-1)*COLS+COLS/2+1):(NaN):xtic(myXtic(n))
    set output
    ### end of script
    

    Result:

    My GhostView as EPS viewer doesn't work with together with the latest version of GhostScript. So, I used IrfanView together with GhostScript, but I'm not sure whether the color representation is correct, e.g. if I set color to black or 0x000000, I still get only a grey shade.

    enter image description here