2

I am attempting to create a graph showing some results, and to plot SI units on the left Y-axis and Imperial units on the right y-axis. My MWE so far is getting close, but as you can see from the screenshot the right Y-axis is not scaled properly nor is it in the correct location. What am I missing for the right Y-axis to get this displayed properly?

\documentclass[letterpaper]{article}

\usepackage{pgfplots} \pgfplotsset{compat=1.16}

\begin{document}

\begin{figure} \begin{center} \begin{tikzpicture} \begin{axis}[% width=\linewidth, xmin=0, xmax=200, ymin=0, ymax=500, domain=2:200, range=0:700, samples=101, axis y line=left, restrict y to domain =0:700, yticklabel style={ /pgf/number format/fixed, /pgf/number format/precision=0 }, scaled y ticks=false, xlabel={Dimension Ratio $DR$}, ylabel={Allowable Pressure (kPa)}, every axis plot/.append style={ultra thick}, legend pos=south west ] % \addplot[ smooth, color=black, ] plot {0.05/0.1(2205000/(3(x-1)^3)+0.0610.40)1000}; \addlegendentry{$E' = 0.40$ MPa} % \end{axis} \begin{axis}[ axis y line*=right, axis x line=none, xmin=0, xmax=1, ymin=0, ymax=10442.72, ylabel={Allowable Pressure (psf)}, yticklabel style={ /pgf/number format/fixed, /pgf/number format/precision=0 }, scaled y ticks=false, ] \end{axis} \end{tikzpicture} \end{center} \caption{Allowable Pressure} \end{figure}

\end{document}

figure

Torbjørn T.
  • 206,688
grfrazee
  • 969
  • 1
    You need to set the same size (width) for both axes. – Torbjørn T. Oct 06 '20 at 19:45
  • 1
    Unrelated: \addplot [..] plot {...}; -> \addplot [..] {...};, you don't need the plot keyword there. – Torbjørn T. Oct 06 '20 at 19:53
  • @Torbjørn T., thanks, that definitely fixed the size and position, but now the right Y-axis is jammed into the right margin. Any ideas on how to fix that besides setting the width as something less than \linewidth? – grfrazee Oct 06 '20 at 20:01
  • Not really, no. You can of course put the whole tikzpicture in a resizebox, but that will of course resize the text as well. – Torbjørn T. Oct 06 '20 at 20:11
  • @Torbjørn T., ok, if you want to write this up an an answer, I'll accept it so you get the credit :) – grfrazee Oct 06 '20 at 22:20
  • See "4.9.11 Two Ordinates (y-axis) or Multiple Axes" in the pgfplots-manual too. – cis Oct 06 '20 at 23:39

1 Answers1

2

The two axes must have the same size. You've changed the size of only one of them with width=\linewidth, so add the same for the other axis.

Other comments:

  • If there are multiple settings that are common between the two axes, you can make a style with e.g.

    \pgfplotsset{myaxis/.style={width=0.9\linewidth, <other settings>}}
    

    and then use

    \begin{axis}[myaxis, ..
    
  • The plot keyword you used in \addplot [...] plot {..}; is unnecessary (and makes kind of a mix between the plain TikZ \draw plot and the pgfplots \addplot), I'd use just \addplot [...] {..};.

  • In general use \centering instead of the center environment inside floats, see Should I use center or centering for figures and tables?

Torbjørn T.
  • 206,688