Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you plot bar charts in gnuplot?

How do you plot bar charts in gnuplot with text labels?

like image 221
tatwright Avatar asked Nov 29 '08 14:11

tatwright


People also ask

How use gnuplot to plot data from a file?

To plot functions simply type: plot [function] at the gnuplot> prompt. Discrete data contained in a file can be displayed by specifying the name of the data file (enclosed in quotes) on the plot or splot command line. Data files should have the data arranged in columns of numbers.

Which Pyplot method is used to make bar charts?

To create a bar chart with pyplot, we use the plt. bar() function.

Is gnuplot easy?

Running gnuplot is easy: from a command prompt on any system, type gnuplot. It is even possible to do this over a telnet or ssh connection, and preview the graphs in text mode!

What is gnuplot used for?

What is gnuplot? gnuplot is a command-driven interactive function plotting program. It can be used to plot functions and data points in both two- and three- dimensional plots in many different formats. It is designed primarily for the visual display of scientific data.


1 Answers

Simple bar graph:

bar graph

set boxwidth 0.5 set style fill solid plot "data.dat" using 1:3:xtic(2) with boxes 

data.dat:

0 label       100 1 label2      450 2 "bar label" 75 

If you want to style your bars differently, you can do something like:

multi color bar graph

set style line 1 lc rgb "red" set style line 2 lc rgb "blue"  set style fill solid set boxwidth 0.5  plot "data.dat" every ::0::0 using 1:3:xtic(2) with boxes ls 1, \      "data.dat" every ::1::2 using 1:3:xtic(2) with boxes ls 2 

If you want to do multiple bars for each entry:

data.dat:

0     5 0.5   6   1.5   3 2     7   3     8 3.5   1 

gnuplot:

set xtics ("label" 0.25, "label2" 1.75, "bar label" 3.25,)  set boxwidth 0.5 set style fill solid  plot 'data.dat' every 2    using 1:2 with boxes ls 1,\      'data.dat' every 2::1 using 1:2 with boxes ls 2 

barchart_multi

If you want to be tricky and use some neat gnuplot tricks:

Gnuplot has psuedo-columns that can be used as the index to color:

plot 'data.dat' using 1:2:0 with boxes lc variable 

barchart_multi2

Further you can use a function to pick the colors you want:

mycolor(x) = ((x*11244898) + 2851770) plot 'data.dat' using 1:2:(mycolor($0)) with boxes lc rgb variable 

barchart_multi3

Note: you will have to add a couple other basic commands to get the same effect as the sample images.

like image 171
Brad Avatar answered Sep 21 '22 11:09

Brad