[Tex/LaTex] Parametric plot using pgfplots package

graphspgfplots

I want to make a parametric plot using pgfplot in LaTex. My equations are

\rho= K (sinh t-t)
P= 1/3 K (sinh t - 8 sinh (1/2) t +3t)
with K=1\pi

I have written the LaTex code for equations , now please help me plot the graph

\documentclass[12pt,a4paper]{article}
\usepackage[a4paper, total={6in, 8in}]{geometry}
    \usepackage[utf8]{inputenc}
    \usepackage[T1]{fontenc}
    \usepackage{fourier}
    \usepackage{mathtools}
\usepackage{amsmath}
\usepackage[english]{babel}
\usepackage{graphicx}
\usepackage{marginnote}
\begin {document}

\underline {Chandrashekhar EOS (1935)} : \\
\begin{align*}
\overline \rho &= K ~\Big( \sinh ~t ~- ~t\Big)\\
\overline P &= \frac {1}{3} K ~ \Big(\sinh~t -~ 8~ \sinh \frac {1}{2} t  +~ 3t\Big)\\
 K &= \frac {1}{4\pi}\\
\end {align*}
\end {document}

Best Answer

Another fun with PSTricks. It really uses the parametric approach in question.

\documentclass[pstricks,border=0pt,12pt,dvipsnames]{standalone}
\usepackage{pst-plot,pst-math,amsmath}
\usepackage[nomessages]{fp}

\FPeval\XMin{0-6}
\FPeval\XMax{7}
\FPeval\YMin{0-6}
\FPeval\YMax{6}

\FPeval\XOL{0-1/3} % of DeltaX
\FPeval\XOR{1/3} % of DeltaX
\FPeval\YOB{0-1/3} % of DeltaY
\FPeval\YOT{1/3} % of DeltaY

%\FPset\TrigLabelBase{3}
\FPeval\DeltaX{1}
\FPeval\DeltaY{1}

\FPeval\AxisL{XMin+DeltaX*XOL}
\FPeval\AxisR{XMax+DeltaX*XOR}
\FPeval\AxisB{YMin+DeltaY*YOB}
\FPeval\AxisT{YMax+DeltaY*YOT}

\newlength\Width\Width=12cm


\newlength\llx\llx=-5pt
\newlength\urx\urx=15pt
\newlength\lly\lly=-5pt
\newlength\ury\ury=15pt


\psset
{
    llx=\llx,
    lly=\lly,
    urx=\urx,
    ury=\ury,
    %xtrigLabels,
    %ytrigLabels,
    %trigLabelBase=\TrigLabelBase,
    labelFontSize=\scriptstyle,
    xAxisLabel=$x$,
    yAxisLabel=$y$,
    algebraic,
    plotpoints=500,
    yMaxValue=\YMax,
    yMinValue=\YMin,
}

\pstVerb{/K {.25 Pi div} def}
\def\x{t}
\def\yp{K*(SINH(t)-t)}
\def\yP{K/3*(SINH(t)-8*SINH(t/2)+3*t)}




\begin{document}
\pslegend[bt](80,0)
{
    \color{NavyBlue}\rule{12pt}{3pt} & \color{NavyBlue} $\overline{p} = K (\sinh t -t) $ \\
    \color{Maroon}\rule{12pt}{3pt}   & \color{Maroon} $\overline{P} = \tfrac{1}{3} K (\sinh t -8 \sinh (\tfrac{1}{2}t)+3t) $ \\
                                     & where $K=\frac{1}{4\pi}$
}
\begin{psgraph}
    [
        dx=\DeltaX,
        dy=\DeltaY,
        Dy=\DeltaY,
        Dx=\DeltaX,
        linecolor=gray,
        tickcolor=gray,
        ticksize=-3pt 3pt,
        axespos=top,
    ]{<->}(0,0)(\AxisL,\AxisB)(\AxisR,\AxisT){\dimexpr\Width-\urx+\llx}{!}
    \psaxes
    [
        dx=\DeltaX,
        dy=\DeltaY,
        labels=none,
        subticks=5,
        tickwidth=.4pt,
        subtickwidth=.2pt,
        tickcolor=Red!30,
        subtickcolor=ForestGreen!30,
        xticksize=\YMin\space \YMax,
        yticksize=\XMin\space \XMax,
        subticksize=1,
    ](0,0)(\XMin,\YMin)(\XMax,\YMax)
    \psparametricplot[linecolor=NavyBlue]{\XMin}{7}{\x|\yp}
    \psparametricplot[linecolor=Maroon]{\XMin}{7}{\x|\yP}
\end{psgraph}
\end{document}

enter image description here

Notes for ShareLaTeX users

Go to upper left menu, and you will see the following. Change as pointed by the red arrow. And don't forget to recompile.

enter image description here

The lastest update based on OP's comment

\documentclass[pstricks,border=0pt,12pt,dvipsnames]{standalone}
\usepackage{pst-plot,pst-math,amsmath}
\usepackage[nomessages]{fp}

% Be careful, fp has not defined 
% the unary negate so we have to write 0-8 to represent -8 for example.

\FPeval\XMin{0-0}
\FPeval\XMax{7}
\FPeval\YMin{0-0}
\FPeval\YMax{6}

\FPeval\XOL{0-0} % of DeltaX
\FPeval\XOR{1/3} % of DeltaX
\FPeval\YOB{0-0} % of DeltaY
\FPeval\YOT{1/3} % of DeltaY

%\FPset\TrigLabelBase{3}
\FPeval\DeltaX{1}
\FPeval\DeltaY{1}

\FPeval\AxisL{XMin+DeltaX*XOL}
\FPeval\AxisR{XMax+DeltaX*XOR}
\FPeval\AxisB{YMin+DeltaY*YOB}
\FPeval\AxisT{YMax+DeltaY*YOT}

\newlength\Width\Width=12cm


\newlength\llx\llx=-20pt
\newlength\urx\urx=15pt
\newlength\lly\lly=-20pt
\newlength\ury\ury=15pt


\psset
{
    llx=\llx,
    lly=\lly,
    urx=\urx,
    ury=\ury,
    %xtrigLabels,
    %ytrigLabels,
    %trigLabelBase=\TrigLabelBase,
    labelFontSize=\scriptstyle,
    xAxisLabel=$x$,
    yAxisLabel=$y$,
    algebraic,
    plotpoints=500,
    yMaxValue=\YMax,
    yMinValue=\YMin,
}

\pstVerb{/K {.25 Pi div} def}
\def\x{t}
\def\yp{K*(SINH(t)-t)}
\def\yP{K/3*(SINH(t)-8*SINH(t/2)+3*t)}




\begin{document}
\pslegend[rt]%(80,0)
{
    \color{NavyBlue}\rule{12pt}{3pt} & \color{NavyBlue} $\overline{p} = K (\sinh t -t) $ \\
    \color{Maroon}\rule{12pt}{3pt} & \color{Maroon} $\overline{P} = \tfrac{1}{3} K (\sinh t -8 \sinh (\tfrac{1}{2}t)+3t) $ \\
    & where $K=\frac{1}{4\pi}$
}
\begin{psgraph}
    [
        dx=\DeltaX,
        dy=\DeltaY,
        Dy=\DeltaY,
        Dx=\DeltaX,
        linecolor=gray,
        tickcolor=gray,
        ticksize=-3pt 3pt,
        axespos=top,
    ]{->}(0,0)(\AxisL,\AxisB)(\AxisR,\AxisT){\dimexpr\Width-\urx+\llx}{!}
    \psaxes
    [
        dx=\DeltaX,
        dy=\DeltaY,
        labels=none,
        subticks=5,
        tickwidth=.4pt,
        subtickwidth=.2pt,
        tickcolor=Red!30,
        subtickcolor=ForestGreen!30,
        xticksize=\YMin\space \YMax,
        yticksize=\XMin\space \XMax,
        subticksize=1,
    ](0,0)(\XMin,\YMin)(\XMax,\YMax)
    \psparametricplot[linecolor=NavyBlue]{\XMin}{7}{\x|\yp}
    \psparametricplot[linecolor=Maroon]{\XMin}{7}{\x|\yP}
\end{psgraph}
\end{document}

enter image description here

Related Question