Graphics, Figures & TablesPgfplots with left and right y-axis (2 scales)

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
dorien
Posts: 7
Joined: Thu Jan 28, 2010 12:52 pm

Pgfplots with left and right y-axis (2 scales)

Post by dorien »

Hi,

I am trying to get a plot with a left and right y axis, to plot 2 different plots in one.

I was able to do this with stack, but when both graphs go down, they seem to overlap, so you cannot see one of them... Therefore I wanted to change them into nice bar charts perhaps. Any idea on how I do this? When I use ybar, the stack doesn't work anymore...

Another thing, I am also trying to remove the subdivisions from the axis, so it only says 0 and 1 on the x axis.

Code: Select all

\begin{figure}
\caption{Means plot for NH2 (CP)}
 \begin{tikzpicture}[scale=1]
 \begin{axis}[stack plots=y,
 axis x line=bottom,
 axis y line=left,
axis z line=right,
 xlabel=$N_2$,
 ylabel=Score]
 \addplot[color=black, mark=*, mark options={fill=white}] coordinates {
(0 , 1.7797252921)
(1 , 0.8648765802)
 };
\end{axis} 
\begin{axis}[stack plots=y,
 axis x line=bottom,
 axis y line=right,
axis z line=right,
 xlabel=$N_2$,
 ylabel=Time]
 \addplot[color=black, dotted, mark=*, mark options={fill=white}] coordinates {
 (0.0 , 94.577421875)
 (1.0 , 77.7847366898)
 };
 \end{axis}
 \end{tikzpicture}
\label{fig:mnh1}
\end{figure}

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

Post Reply