How to Create a Histogram in Latex: Step-by-Step Guide

  • Context: LaTeX 
  • Thread starter Thread starter CourtneyS
  • Start date Start date
  • Tags Tags
    histogram latex
Click For Summary
SUMMARY

This discussion focuses on creating a histogram in LaTeX using the pst-plot package. The user seeks to automate the process by generating a list of frequency data from a computer program and importing it into LaTeX. The provided LaTeX code demonstrates how to plot the histogram using predefined data points. For further assistance, users are encouraged to consult the CTAN website or the comp.text.tex newsgroup for additional resources and packages.

PREREQUISITES
  • Familiarity with LaTeX document preparation system
  • Understanding of the pst-plot package for plotting in LaTeX
  • Basic programming skills to generate and output data files
  • Knowledge of data formatting for LaTeX input
NEXT STEPS
  • Explore the CTAN website for additional LaTeX packages related to data visualization
  • Learn how to output data from programming languages (e.g., Python, R) to text files
  • Investigate the comp.text.tex newsgroup for community support and existing solutions
  • Study advanced features of the pst-plot package for enhanced histogram customization
USEFUL FOR

This discussion is beneficial for LaTeX users, data analysts, and programmers looking to visualize frequency distributions through histograms in their documents.

CourtneyS
Messages
23
Reaction score
0

Homework Statement


Hi,
I need to create a histogram in Latex.
I know how to do this,
however,
I only know how to do it if I have a limited number of points so I want it so that I can get a
computer program to generate a list of numbers and save them to a file and then I can import this to Latex and use it this way in the Histogram.

Homework Equations

The Attempt at a Solution



\documentclass{article}

\usepackage{pst-plot}

\savedata{\data}[{{0.5,1},{1,7},{1.5,1},{2,3},{2.5,1},{3,2},{3.5,1}}]

\begin{document}

\psset{xunit = 2}
\begin{pspicture}(-0.23,-0.53)(4,7.5)
\listplot[
plotstyle = bar,
barwidth = 0.8,
linecolor = red,
fillstyle = solid,
fillcolor = blue!70
]{\data}
\psaxes[
Dx = 0.5,
xticksize = -4pt 0
]{->}(4,7.5)
\end{pspicture}

\end{document}This is what I am currently using to generate the histogram.
I have a computer program that stores the frequency in which a certain number occurs.
So, if my range in my program was from -10 to 10 it would tell me how many times in this range each number occurred for a certain number of n trials.

How should I get my program to output this data to a file so that I can use it in this histogram?
Thanks
 
Physics news on Phys.org
CourtneyS said:

Homework Statement


Hi,
I need to create a histogram in Latex.
I know how to do this,
however,
I only know how to do it if I have a limited number of points so I want it so that I can get a
computer program to generate a list of numbers and save them to a file and then I can import this to Latex and use it this way in the Histogram.

Homework Equations

The Attempt at a Solution



\documentclass{article}

\usepackage{pst-plot}

\savedata{\data}[{{0.5,1},{1,7},{1.5,1},{2,3},{2.5,1},{3,2},{3.5,1}}]

\begin{document}

\psset{xunit = 2}
\begin{pspicture}(-0.23,-0.53)(4,7.5)
\listplot[
plotstyle = bar,
barwidth = 0.8,
linecolor = red,
fillstyle = solid,
fillcolor = blue!70
]{\data}
\psaxes[
Dx = 0.5,
xticksize = -4pt 0
]{->}(4,7.5)
\end{pspicture}

\end{document}This is what I am currently using to generate the histogram.
I have a computer program that stores the frequency in which a certain number occurs.
So, if my range in my program was from -10 to 10 it would tell me how many times in this range each number occurred for a certain number of n trials.

How should I get my program to output this data to a file so that I can use it in this histogram?
Thanks

I suggest you re-direct your question to the CTAN website, where the TeX/LaTeX experts lurk. There may even be some existing free packages that do what you want, and the Texperts could tell you where to find them.

Alternatively, go to the newsgroup "comp.text.tex" and see if the question has already been addressed.
 
Last edited:

Similar threads

  • · Replies 12 ·
Replies
12
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 1 ·
Replies
1
Views
5K
  • · Replies 0 ·
Replies
0
Views
6K