Graphics, Figures & TablesStatistics and Histograms

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
white_owl
Posts: 12
Joined: Wed Apr 21, 2010 6:56 pm

Statistics and Histograms

Post by white_owl »

I need to draw several statistical charts. With histograms and boxplots (those two are the must!).

Which package can be of more use? For now I just draw everything manually in tikZ, results are pretty but it is very tedious task.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Statistics and Histograms

Post by localghost »

white_owl wrote:[…] Which package can be of more use? […]
Plotting can be done easier by special packages.

Thorsten
feuersaenger
Posts: 34
Joined: Sun Oct 16, 2011 5:56 pm

Re: Statistics and Histograms

Post by feuersaenger »

[EDIT: here a translated variant: sorry, my initial answer was accidentally in german]

Hi,

pgfplots kann compute and draw histograms.

The current "unstable" of pgfplots comes with a "statistics" library which supports boxplots. It can compute the statistics given some sample. It can also take precomputed statistics and visualize them. The unstable will be released eventually, but it can be installed from http://pgfplots.sourceforge.net/ . If you want to see if its features are what you need, you can inspect the online manual from http://pgfplots.sourceforge.net/pgfplots_unstable.pdf (section statistics library).

Kind regards

Christian
reb_will123
Posts: 1
Joined: Thu Dec 19, 2013 7:45 am

Statistics and Histograms

Post by reb_will123 »

You can use the jqchart library jqPlot which is one of the plugin with nice features for doing creating various charts like bar char, pie chart or custom charts.
mgmillani
Posts: 16
Joined: Fri Dec 20, 2013 7:26 pm

Statistics and Histograms

Post by mgmillani »

I generally use gnuplot to generate plots and charts, creating a png image.
As it can be a little complicated to find documentation for gnuplot at first, here is an example to help you get started:

Lets say this is a file called "plotter"

Code: Select all

# Sets the separator of each column,
# which means that every line of the input file should be in the format x:y
set datafile sep ':'

# writes the chart to a png with 1024 pixels of width and 768 of height
set terminal png size 1024,768
# where should the file be written
set output 'plot.png'

# distance between each tic in the x axis
set xtics 5

# names of the axes
set xlabel 'X'
set ylabel 'Y (in units)'

# where the legend should be placed
set key outside top

# what should be plotted
files = "file1 file2 file3"
titles = "A B C"

# plots every file, diving y by 1 million. Files are under the data folder
plot for[i=1:words(files)] 'data/'.word(files,i) u 1:($2/1e6) w lines lw 5 title word(titles,i)

# in case you want to plot only one file:
# plot "data/file1" with lines lw 5 title "A"
where file1 is:

Code: Select all

1:200000
2:3000000
3:1050053
4:6543281
14:9879521
file2:

Code: Select all

0:12346578
1.5:1000000
3:2365478
8:654975
and file3:

Code: Select all

1:1000000
2:2000000
3:3000000
and file1,file2,file3 are under the data folder.

Then you would run on a command line:

Code: Select all

gnuplot plotter
and the plot would be written to "plot.png" .
You can also use gnuplot in a interactive way, in case you want to just test stuff, by just calling the program with no arguments.

I never used any plotting package for LaTeX, but I doubt any of the available ones is better than gnuplot.
User avatar
Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Statistics and Histograms

Post by Johannes_B »

pgfplots is very powerful and when you want to plot some data to show in your document it is your first choice. Gnuplot can do some simple calculations (well, in fact pgfplots can calculate some stuff as well), but higher mathematics can't be done with both of them.
The statistics data, that Gnuplot can calc, but pgfplots can't can be written to a text file and fed to pgfplots, in order to print it.

Documentation for Gnuplot isn't really hard to find, it might be hard to find the right keyword.
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
Post Reply