3

I have created a histogram plot with pgfplots as following

    \begin{tikzpicture}
\begin{axis}[small,ymin=0,title=\texttt{hist}]
\addplot [
hist,
fill=orange!75,
draw=orange!50!black]
table [y index=0] {FC.dat};
\end{axis}
\end{tikzpicture}
%
\begin{tikzpicture}
\begin{axis}[small,ymin=0, title=\texttt{hist=density}]
\addplot [
hist=density,
fill=orange!75,
draw=orange!50!black]
table [y index=0] {FC.dat};
\end{axis}
\end{tikzpicture}

FC.dat is the file where the simulation results are stored. There is no specific function to fitting. So maybe connect the central point of each bar is a good idea. hist-bar

I am wondering if there is any way to add a fitting line/envelop to the bar type histogram just as the one I found

Thank you for your help!

enter image description here

  • 1
    Adding the code that you used makes it easier to help you. Do you have a special function, that you want to fit or do you just want to connect the centers of the bar? – jens_bo May 22 '14 at 13:40
  • What is the purpose of the line you're trying to draw? In the example picture you posted, the dashed line represents a theoretical distribution, and overlaying that with the empirical histogram makes it possible to assess whether the theoretical distribution adequately models the data. Simply joining the bars doesn't allow you to do that, though. – Jake May 26 '14 at 10:28
  • @Jake please be noted that the second graph is not created by me. It is just an example from Internet which is illustrated with normal distribution. I do not think it is only meaningful to fitting histogram generated by a specific known distribution function. In most cases, there is no parametric model for the samples observed. The short answer for your question about purpose of doing this is: smooth the histogram and relate histogram with probability density function. – user52228 May 28 '14 at 18:24
  • @Jake there are some reference for this topic at en.wikipedia.org/wiki/Kernel_density_estimation. Anyway, this problem has been solved by matlab2tikz. The solution relies on the plot function 'ksdensity' of Matlab. – user52228 May 28 '14 at 18:27
  • Fair enough, but joining the bars is probably not the best way to smooth the histogram. Proper kernel density estimation is much better for this (and should be doable in PGFPlots with a bit of work) – Jake May 28 '14 at 18:30

Browse other questions tagged or ask your own question.