Graphics, Figures & Tables ⇒ pgfplots | Two y Axes in one Plot
pgfplots | Two y Axes in one Plot
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.
- Attachments
-
- Paper.tex
- MWE that doesn't work.
- (2.6 KiB) Downloaded 730 times
Learn LaTeX easily with newest books:
The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis
The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more
LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis
pgfplots | Two y Axes in one Plot
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}
- 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 44150 times
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
Re: pgfplots | Two y Axes in one Plot
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