Extend x axis on graph?

1,622

Assuming (based on guessing of course...) that your document is two column article. To make graph that not be square but rectangle, is (to my opinion) sufficient to select appropriate width and height of graph:

enter image description here

Image above has ration 4:3, generated is by the following code:

\documentclass[twocolumn]{article}
\usepackage[margin=25mm]{geometry}
\usepackage{lipsum}                 % only for test, in real document must be deleted

\usepackage{pgfplots}
\pgfplotsset{compat=1.14,           % <-- added
            width=\columnwidth,     % <-- added
            height=0.75\columnwidth % <-- added, with this the image is in aspect 4:3
            }

\begin{document}
\lipsum[11]

  \begin{center}
\begin{tikzpicture}
\begin{axis}[
    xlabel=Reynolds Number,
    ylabel=Coefficient Discharge,
    legend style={cells={anchor=west}}      % <-- added
                ]

\addplot [color=blue,mark=*] coordinates {
    (6485.41491,0.408143397)
    (7927.942858,0.407370795)
    (8663.115504,0.38550864)
    (9219.462371,0.366953133)
    (9537.374867,0.346531912)
    (10491.11235,0.330115983)
    (11087.19828,0.312041115)
    (12219.76155,0.313951177)
};
    \addlegendentry{1/4}
\addplot [color=red,mark=triangle] coordinates {
    (6556.945221,   0.412644978)
    (7868.334265,   0.404307857)
    (8663.115504,   0.38550864)
    (9187.671122,   0.365687778)
    (9120.114717,   0.331371141)
    (10443.42548,   0.328615455)
    (11683.28421,   0.328817519)
    (12875.45607,   0.330797337)
};
    \addlegendentry{1/2 Lift}
\addplot [color=black,mark=*] coordinates {
    (6843.066467,   0.430651305)
    (8297.516134,   0.426361012)
    (9203.566747,   0.40955872)
    (8615.42863,    0.342911376)
    (9298.940495,   0.337868614)
    (10824.92047,   0.340619673)
    (11683.28421,   0.328817519)
    (12899.29951,   0.331409925)
};
    \addlegendentry{3/4 Lift}
\addplot [color=yellow,mark=*] coordinates {
    (6854.988186,   0.431401568)
    (8398.850742,   0.431568008)
    (9267.149246,   0.412388141)
    (8567.741755,   0.341013343)
    (9346.62737 ,   0.339601273)
    (10753.39016,   0.338368882)
    (11897.87515,   0.334857025)
    (13030.43841,   0.334779157)
};
    \addlegendentry{Full Lift}
\end{axis}%
\end{tikzpicture}
\end{center}
\lipsum[2]
\end{document}

As you can see, I delete scale option. It can become an evil. Better is define image size in advance. and left to pgfplots to accommodate graphs to prescribed size.

Share:
1,622

Related videos on Youtube

user127841
Author by

user127841

Updated on August 09, 2021

Comments

  • user127841
    user127841 about 2 years

    I'd like to extend my x axis a little longer. Is it possible to do that?

    \centering
        \begin{tikzpicture}[scale=1.5]
    
        \begin{axis}[
            xlabel=Reynolds Number,ylabel=Coefficient Discharge]
        \addplot [color=blue,mark=*] coordinates {
            (6485.41491,0.408143397)
            (7927.942858,0.407370795)
            (8663.115504,0.38550864)
            (9219.462371,0.366953133)
            (9537.374867,0.346531912)
            (10491.11235,0.330115983)
            (11087.19828,0.312041115)
            (12219.76155,0.313951177)
        };
            \addlegendentry{1/4}
        \addplot [color=red,mark=triangle] coordinates {
            (6556.945221,   0.412644978)
            (7868.334265,   0.404307857)
            (8663.115504,   0.38550864)
            (9187.671122,   0.365687778)
            (9120.114717,   0.331371141)
            (10443.42548,   0.328615455)
            (11683.28421,   0.328817519)
            (12875.45607,   0.330797337)
        };
            \addlegendentry{1/2 Lift}
        \addplot [color=black,mark=*] coordinates {
            (6843.066467,   0.430651305)
            (8297.516134,   0.426361012)
            (9203.566747,   0.40955872)
            (8615.42863,    0.342911376)
            (9298.940495,   0.337868614)
            (10824.92047,   0.340619673)
            (11683.28421,   0.328817519)
            (12899.29951,   0.331409925)
        };
            \addlegendentry{3/4 Lift}
        \addplot [color=yellow,mark=*] coordinates {
            (6854.988186,   0.431401568)
            (8398.850742,   0.431568008)
            (9267.149246,   0.412388141)
            (8567.741755,   0.341013343)
            (9346.62737 ,   0.339601273)
            (10753.39016,   0.338368882)
            (11897.87515,   0.334857025)
            (13030.43841,   0.334779157)
        };
            \addlegendentry{Full Lift}
        \end{axis}%
    \end{tikzpicture}%
    

    enter image description here

    • Jānis Lazovskis
      Jānis Lazovskis over 6 years
      How much is "a little"? Up until 1.6, 1.8, 2? And to the right or also left? Do you want to keep the same ratio of the graph sides? Also, please include all the code necessary to compile the document with your results, from \documentclass to \end{document}.
    • MS-SPO
      MS-SPO over 2 years
      @user127841, Just some remark on content: it is very rare, that curves like this "travel backwards". I.e. the yellow and black data seem to have some trouble, and to some degree the red one, too. // Perhaps the line connectors reflect the sequence of measurements? Still, it would be better to drop lines at all (sequence is no relevant piece of information - think of "repeat and reproduce", by anyone, anywhere, anytime). Instead, measurement error IS relevant information, which can aslo be visualized.