Search code examples
gnuploterrorbar

Gnuplot: Errorbars with variable style


I want to plot data with errorbars, where the points are quite dense and have rather different errors. I would like the "good" points (i.e. small error) to be quite prominent, and the "bad" points (i.e. large error) to be less visible, because I don't want the bad points to dominate the overall picture. This could be achieved by dynamically changing the line width or transparency.

What I come up so far is to use a hard cut-off and plot the data twice: All points with a small error (<=0.1) with a solid line colour, and all points with a large error (>0.1) with increased transparency.

$data << EOD
535.66534   1.553616310747869   0.08061677996455376
536.15027   1.520824866288427   0.05828386048268186
537.38049   1.332803196338175   0.235778491140896
537.64696   1.479699311985051   0.3751992204089783
540.20631   1.497105281091503   0.04237229839015798
541.41537   1.320918189513518   0.4115091427635642
542.00647   1.47517488483194    0.3873921664923128
543.51616   1.515846650015762   0.0471200695087297
545.00234   1.538963623338375   0.1611245310026408
556.4311    1.606343443386191   0.04973685496066002
EOD
plot $data u 1:($3>0.1 ? 1/0 : $2):3 w yerrorbars lc 1, '' u 1:($3<=0.1 ? 1/0 : $2):3 w yerrorbars lc rgb "#aa9400d3"

But this is a rather hard-coded solution. A more dynamic picture, where each point's transparency is individually calculated from the size of its error, would be nicer and smoother. Does anyone have an idea how to achieve this? Alternate suggestions for "hiding" bad points are welcome as well!


Solution

  • Using a palette might be a starting point:

    set palette defined ( 0 "blue", 1 "white" ) 
    # unset colorbox
    plot $data u 1:2:3:3 w yerrorbars lc palette z lw 2 
    

    It does not use transparency, instead, it changes the color from blue to white. Gnuplot automatically selects an appropriate cbrange, 0 to 0.45 in this case. The value 0 would correspond to blue, 0.45 would correspond to white. You can adjust this range with set cbrange if necessary. The colorbox can be suppressed with unset colorbox. See help palette and help rgbcolor for more information.

    This is the result:

    error bar depending on error