Dear All,
I would to have two plots on the same plot (hence two different y axes). While each plot can be easily obtained separately, I am struggling to plot them all together (actually none of them work). Another issue is that the label for the right y axis appears on the left of the left y axis.
Please find attached a MWE, based on an example found in the pgfplots Gallery. If this is not feasible, what other method can I use (Gnuplot should work)?
Thank you.
Sincerely.
Graphics, Figures & Tables ⇒ pgfplots | Two y Axes in one Plot
pgfplots | Two y Axes in one Plot
- Attachments
-
- Paper.tex
- MWE that doesn't work.
- (2.6 KiB) Downloaded 718 times
TeX Live 2012 and Texmaker 4.0.2
NEW: TikZ book now 40% off at Amazon.com for a short time.

pgfplots | Two y Axes in one Plot
It seems you need to specify the domain. The position of the label of the right y axis is a bit hacked in the example below but it seems to work:
Regards
Code: Select all
\documentclass{article}
\usepackage{pgfplots}
\usepackage{siunitx}
\DeclareSIUnit\fahrenheit{\degree F}
\DeclareSIUnit\pound{lbm}
\sisetup{per-mode=symbol}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
xmin = 700, xmax = 2000,
ymin = 0, ymax = 50,
axis y line* = left, % the '*' avoids arrow heads
xlabel = $p_0 \, \mathrm{(psi)}$,
ylabel = $\dot{m}_{choked} \, (\si{\pound\per\second})$]
\addplot[red,domain=700:2000]{0.019*x};
\end{axis}
\begin{axis}[
xmin = 750, xmax = 2000,
ymin = 1400, ymax = 1800,
hide x axis,
hide y axis]
\addplot[blue,domain=750:1800]{4800*(4.5/x)^(0.2)};
\end{axis}
\pgfplotsset{every axis y label/.append style={rotate=180,yshift=9.5cm}}
\begin{axis}[
xmin=0, xmax=1,
ymin=1400, ymax=1800,
hide x axis,
axis y line*=right,
ylabel={$T_e \, (\si{\fahrenheit})$}
]
\end{axis}
\end{tikzpicture}
\end{document}
site moderator & package author
- localghost
- Site Moderator
- Posts: 9202
- Joined: Fri Feb 02, 2007 12:06 pm
pgfplots | Two y Axes in one Plot
This can be done a bit easier by thecgnieder wrote:[…] The position of the label of the right y axis is a bit hacked in the example below but it seems to work […]
ylabel near ticks
option for the axis
environment.
Code: Select all
\documentclass{standalone}
\usepackage{mathtools}
\usepackage{pgfplots}
\usepackage{siunitx}
\sisetup{per-mode=symbol}
\DeclareSIUnit{\fahrenheit}{\degree F}
\DeclareSIUnit{\pound}{lbm}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
xmin=700,xmax=2000,
ymin=0,ymax=50,
axis y line*=left,
xlabel={$p_0$ (psi)},
xlabel near ticks,
ylabel={$\dot{m}_\text{choked}$ (\si{\pound\per\second})},
ylabel near ticks
]
\addplot[red,domain=700:2000]{0.019*x};
\end{axis}
\begin{axis}[
xmin = 750, xmax = 2000,
ymin = 1400, ymax = 1800,
hide x axis,
axis y line*=right,
ylabel={$T_e$ (\si{\fahrenheit})},
ylabel near ticks
]
\addplot[blue,domain=750:1800]{4800*(4.5/x)^(0.2)};
\end{axis}
\end{tikzpicture}
\end{document}
- Attachments
-
- The resulting output.
- pgfplots-two-y-axis.png (12.55 KiB) Viewed 43540 times
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
Re: pgfplots | Two y Axes in one Plot
Thanks a lot for your help, cgnieder and localghost. This is awesome!
I only found afterwards three websites dealing with plotting with pgfplots (could be useful for someone else):
http://tex.stackexchange.com/questions/ ... ng-pgfplot
http://tex.stackexchange.com/questions/ ... is-scaling
http://www.latex-community.org/forum/vi ... 45&t=12560
Regards,
Heresy
I only found afterwards three websites dealing with plotting with pgfplots (could be useful for someone else):
http://tex.stackexchange.com/questions/ ... ng-pgfplot
http://tex.stackexchange.com/questions/ ... is-scaling
http://www.latex-community.org/forum/vi ... 45&t=12560
Regards,
Heresy
TeX Live 2012 and Texmaker 4.0.2