Gnuplot Boxes Error Bars
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies gnuplot boxerrorbars of this site About Us Learn more about Stack Overflow the company Business gnuplot error bars style Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask gnuplot bar chart Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign gnuplot xtic up Adding error bars on a bar graph in gnuplot up vote 7 down vote favorite 2 I have the following file I want to plot using gnuplot bar graphs: Function X X-ERROR Y Y-ERROR A 1.311539 0.066268 1.000000 0.000000 (a1,b0) 1.325429 0.083437 1.010926 0.016710 (a.9,.b1) 1.134640 0.040017 1.276168 0.060281 (a.8,.b2) 1.078336 0.058529 1.346358 0.054645 (a.7,.b3) 1.035866 0.060660 1.318395 0.018087 (a.6,.b4) 0.982717
Gnuplot Using
0.047363 1.196714 0.047427 (a.5,.b5) 0.962423 0.051994 1.127991 0.044731 (a.4,.b6) 0.953673 0.046014 1.139608 0.044726 (a.3,.b7) 0.948948 0.050462 1.169209 0.044333 (a.2,.b8) 0.941013 0.047166 1.198138 0.045844 (a.1,.b9) 0.929961 0.057801 1.328111 0.088813 (a0,b1) 0.966331 0.036079 3.289381 0.213192 B 1.000000 0.000000 3.321802 0.121290 I can manage to plot the graph perfectly using: plot 'file.dat' using 4:xtic(1) title col, \\ '' using 2:xtic(1) title col; However I would like to use columns 3 and 5 to represent the interval of confidence that I always calculated. Any help? Thanks! gnuplot share|improve this question edited Jul 5 '12 at 15:25 Sirko 42.5k1069105 asked Jul 5 '12 at 15:20 Dynelight 7622833 add a comment| 2 Answers 2 active oldest votes up vote 9 down vote accepted Assuming you want to draw side-by-side bar charts with associated error bars, I would use the following: set xrange [-0.5:12.75] set xtic rotate by -45 set boxwidth 0.25 plot 'file.dat' using ($0-.05):4:5:xtic(1) with boxerrorbars title col, \\ '' using ($0+0.25):2:3 with boxerrorbars title col The idea is just to offset one of the two measures on the x-axis. share|improve this answer answered Jul 9 '12 at 10:47 chl
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business
Gnuplot Script
Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation gnuplot tutorial Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Gnuplot Bar chart with error bars up vote 1 down vote favorite I have the following data Name Value of the bar Confidence interval A http://stackoverflow.com/questions/11347444/adding-error-bars-on-a-bar-graph-in-gnuplot 0.62 [0.59 0.63] B 0.64 [0.54 0.72] C 0.51 [0.46 0.67] D 0.33 [0.25 0.36] I tried to plot it as a bar chart with A,B,C and D labeling each bar and with and error bar. By using plot "my.dat" using 1; with boxes I only get a bar chart. Can someone help me? gnuplot bar-chart axis-labels share|improve this question asked Jul 21 '14 at 18:17 Samuel 475 add a comment| 1 Answer 1 active http://stackoverflow.com/questions/24871941/gnuplot-bar-chart-with-error-bars oldest votes up vote 1 down vote If you also want errorbars, you must add a second plot with the yerrorbars plotting style. The brackets aren't very handy in the data file, so I remove them with a sed command: set style fill solid set boxwidth 0.8 set yrange [0:*] unset key plot "< sed 's/[][]//g' my.dat" using 0:2:xtic(1) with boxes, \ '' using 0:2:3:4 with yerrorbars lc rgb 'black' pt 1 lw 2 share|improve this answer answered Jul 21 '14 at 19:21 Christoph 29.5k72847 Thank you! That's what I wanted. –Samuel Jul 22 '14 at 8:28 Is there any possibility to change the color of the bars? So that each bar has a different color or pattern (filled with dots or lines) –Samuel Jul 22 '14 at 16:05 Yes, you can use e.g. lc variable to color the bars based on some value (possible the row number): plot "< sed 's/[][]//g' my.dat" using 0:2:0:xtic(1) lc variable with boxes. –Christoph Jul 22 '14 at 18:25 add a comment| Your Answer draft saved draft discarded Sign up or log in Sign up using Google Sign up using Facebook Sign up using Email and Password Post as a guest Name Email Post as a guest Name Email discard By posting your answer, you agree to the privacy policy and terms
30.34 22.58 161.08 2011-01-15 23.83 20.33 104.00 2011-01-22 50.50 16.17 79.75 2011-01-29 67.59 21.74 99.25 2011-02-05 37.58 33.33 155.33 2011-02-12 48.17 44.33 66.00 2011-02-19 89.34 12.42 91.42 2011-02-26 113.09 35.83 123.34 2011-04-02 174.25 105.25 221.25 2011-04-09 98.09 55.92 109.00 2011-04-16 98.67 30.83 202.00 2011-04-23 87.17 58.25 http://psy.swansea.ac.uk/staff/carter/gnuplot/gnuplot_histograms.htm 127.09 2011-04-30 139.74 67.33 232.84 2011-04-30 20.0 10.0 30.0 Note that there are two entries http://www.gnuplotting.org/tag/errorbars/ (the last two lines) for 2011-04-30; this is intentional (to demonstrate a point about time-based x values). As described in my page on time-based histograms, gnuplot does not support date/time values (as opposed to labels) for the x axis. Hence, there is no gap where March should be, and 2011-04-30 appears twice in the following plots. Try using set xdata time and you'll error bars see what I mean; you'll get the error message "need full using spec for x time data". Similarly, set timefmt and set xdata time will have no effect. The following plot commands are common to all four of the histograms shown in this page. clear reset unset key # Make the x axis labels easier to read. set xtics rotate out # Select histogram data set style data histogram # Give the bars a plain fill pattern, and draw gnuplot boxes error a solid line around them. set style fill solid border Clustered With the clustered style, one column in the data file corresponds to one bar in the plot, whilst the lines of the data file correspond to the clusters of the bars. Thus, using the following plot commands, we get three bars in each cluster, and one cluster for each row (notice the two clusters for 2011-04-30, which is what we expect). set style histogram clustered plot for [COL=2:4] 'date_mins.tsv' using COL:xticlabels(1) title columnheader Figure 1: Clustered Histogram Note the use of the for feature. This allows us to select multiple columns (2 to 4, in this case); without the for, we'd only be able to plot one column of data (using something like plot 'date_mins.tsv' using 3:xticlabels(1)), which defeats the purpose of the clustered histogram: Errorbars The next histogram type is errorbars. For this, gnuplot can accept up to three columns for y values: the main value for the height of the bar, and a minimum and maximum value for the errorbar. Thus: # We need to set lw in order for error bars to actually appear. set style histogram errorbars linewidth 1 # Make the bars semi-transparent so that the errorbars are easier to see. set style fill solid 0.3 set bars front plot 'date_mins.tsv' using 2:3:4:xticlabels(1) title columnheader This code uses column two for the bar size, column three for the
the last entry we had mean and standard variation data for five different conditions. Now let us assume that we have only two different conditions, but have measured with three different instruments A, B and C. We have used a ANOVA to verify that the data for the two conditions are significant different. As a result the plot in Fig. 1 should be created. Fig. 1 Plot the mean and variance of the given data (code to produce this figure) Therefore we store our data in a format, that can be used by the index command in Gnuplot. Note that the data have two empty lines between the blocks in the real data file: # mean std # A 0.77671 0.20751 0.33354 0.30969 # B 0.64258 0.22984 0.19621 0.22597 # C 0.49500 0.31147 0.14567 0.21857 Now every instrument is stored in a different data block containing both conditions as columns. The color definitions and axes settings are done in a similar way as in the previous blog entry. Note that we have to define two more colors for the boxes, because we use three different colors. Also we define a black line to plot the significance indicator (arrow). set style line 1 lc rgb 'gray30' lt 1 lw 2 set style line 2 lc rgb 'gray40' lt 1 lw 2 set style line 3 lc rgb 'gray70' lt 1 lw 2 set style line 4 lc rgb 'gray90' lt 1 lw 2 set style line 5 lc rgb 'black' lt 1 lw 1.5 set style fill solid 1.0 border rgb 'grey30' The significance indicator is created by three black arrows and a text label: # Draw line for significance test set arrow 1 from 0,1 to 1,1 nohead ls 5 set arrow 2 from 0,1 to 0,0.95 nohead ls 5 set arrow 3 from 1,1 to 1,0.95 nohead ls 5 set label '**' at 0.5,1.05 center For the plot the index command is used to plot first condition A, then B and then C by using block 0,1, and 2 respectively. The x-position of the boxes for instrument A are slightly shifted to the left, the ones for C to the right by subtracting or adding the value of bs. The value of bs has the width of one box in order to plot the boxes side by side. # Size of one box bs = 0.2 # Plot mean with variance (std^2) as boxes with yerrorbar plot 'statistics.dat' i 0 u ($0-bs):1:($2**2) notitle w yerrorb ls 1, \ '' i 0 u ($0-bs):1:(bs) t 'A' w boxes ls 2, \ '' i 1 u 0:1:($2**2) notitle w yerrorb ls 1, \ '' i 1 u 0:1:(bs) t 'B' w boxes ls 3, \ '' i 2 u ($0+bs):1:($2**2) notitle w yerrorb ls 1, \ '' i 2 u ($0+bs):1:(bs) t 'C' w boxes ls 4 Tags: ANOVA, border, boxes, data, errorbars, index Plotting simple statistical data September 9th, 2010 | No Comments If we have done a experiment in order to apply a significance test like a AN