1

So far, I am very obsessed with Tikz though I am a newbie. I am wondering how to plot box chart with normal distribution curve as the picture below?enter image description here

This screenshot is from OriginPro Galley, I dont have the original data. So I assume data like this :

(0.12,0.33,0.34,0.54,0.68.0.67,0.78,1.02,1.11,0.45) (0.13,0.34,0.37,0.33,0.41,0.45,0.47,0.43,0.67,0.87) (0.31,0.42,0.35,0.64,0.72,0.47,0.67,0.87,0.58,0.56)

Any help will be appreciated.

2
  • Do you have the data for the dots? Please show us what you have tried.
    – user194703
    Commented Jan 14, 2020 at 15:34
  • Hi, Schrödinger. I am so sorry for that. This screenshot is from OriginPro Galley, I dont have the original data, and I assume a set of data. I want to try it, but I dont know where to get started.
    – Lerh
    Commented Jan 15, 2020 at 4:28

1 Answer 1

1

I am not sure whether the points are Scatter plot. And it is easy to draw points. So I just plot the box chart with norm distribution curve.

It is mainly based on Rotated Normal Distribution and some boxplot settings can be found in chapter 5.12.1 of Manual.

\documentclass{article}
\usepackage{pgfplots}
\usepackage{tikz}
\pgfplotsset{compat=1.8}
\usepgfplotslibrary{statistics}

\begin{document}
\pgfmathsetmacro{\offset}{0.05}
\begin{tikzpicture}[declare function={gauss(\x,\y,\z)=\offset+1/(\y*sqrt(2*pi))*exp(-((\x-\z)^2)/(2*\y^2));}]

\begin{axis}[samples=101,smooth,height=8cm,
boxplot/draw direction=y]
\addplot [domain=-3:3] ({1+gauss(x,1.2,0)},1+x);
\addplot+ [boxplot prepared={box extend=0.3,draw position=1, lower whisker=-0.5, lower quartile=0.1, median=0.5, upper quartile=.9, upper whisker=2}, ] coordinates {};

\addplot [domain=-3:3] ({3+gauss(x,1.2,0)},x);
\addplot+ [boxplot prepared={draw position=3, lower whisker=-0.5, lower quartile=0.1, median=0.5, upper quartile=.9, upper whisker=2,box extend=0.3}, ] coordinates {};
\end{axis}
\end{tikzpicture}
\end{document}
2
  • Hi, vic156, many thanks. The box and curve are produced by these points. And I assume a set of data, could you please finish the rest part? I'll study it carefully. Many thanks.
    – Lerh
    Commented Jan 15, 2020 at 4:31
  • Hi, lerh. If you want to draw a box chart with data input, The link may help. But the scatter plot needs more information. I mean each point needs a pair of coordinates. But the data you assumed only have a single row for each boxplot.
    – vic156
    Commented Jan 15, 2020 at 5:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .