如何使图形窗口变大?

如何使图形窗口变大?

我正在创建一个 tikz 图表,值非常小。出于某种原因,如果我将每边的宽度设置为大于 4cm,代码将无法执行。我正在尝试将其调整到适合页面。这是我的代码供参考,谢谢:

\documentclass{standalone}
%graph and diagrams
\usepackage{tikz}
\usepackage{pgfplots}
\usetikzlibrary{automata,positioning}

\pgfplotsset{compat=1.12} %remember this line or the graph wont work

\begin{document}
    
\begin{tikzpicture}[every text node part/.style={align=center}] %text after tikzpicture allows for multiline nodes
\begin{axis}[
    title={K Constant as Determined by Mass and Period},
    xlabel={$Mass: \frac{m_2}{m_1+m_2}_{(g)}$},
    ylabel={$Acceleration: (m/s^2)$},
    xmin=0, xmax=.022,
    ymin=0, ymax=.15,
    xtick={0,.002,.004,.006,.008,.01,.012,.014,.016,.018,.02,.022},  
    ytick={0,.0125,.03,.0425,.06,.0725,.09,.1025,.12,.1375,.15},
    legend pos=north west,
    ymajorgrids=true,
    grid style=dashed, %remove for undashed grid
    width=4cm,
    height=4cm,%scale of graph window
    xticklabel style={  %remember this paragraph to prevent scientific notation
        /pgf/number format/fixed,
        /pgf/number format/precision=5
},
]

%legend
    \legend{6.564x}

%linear line
\addplot [
    samples=100, 
    color=blue,
]
{6.564*x};

%data points
 \addplot+[only marks, mark=oplus, color=black] coordinates
      {(.0077,.05)(.0107 ,.07)(.0136,.09)(.0167,.11)(.0196,.13)};
\end{axis}
\end{tikzpicture}

\end{document}

答案1

欢迎来到 TeX:SE!

以下 MWE(最小工作示例):

\documentclass[border=3.141592mm]{standalone}
%graph and diagrams
\usepackage{pgfplots}
\pgfplotsset{compat=1.17} %remember this line or the graph wont work
\usetikzlibrary{automata,positioning}

\usepackage{amsmath}
\usepackage{siunitx}


\begin{document}
    \begin{tikzpicture}
\begin{axis}[width=\linewidth, height=7cm,
    title={K Constant as Determined by Mass and Period},
    xlabel={Mass: $\dfrac{m_2}{m_1+m_2}$ (g)},
    ylabel={Acceleration: (\si{m/s^2})},
    label style={font=\small},
    xmin=0, xmax=.022,
    ymin=0,
    xtick={0,.002,...,0.022},
    legend pos=north west,
    ymajorgrids=true,
    grid style=dashed, %remove for undashed grid
%
    tick label style={font=\scriptsize,
                      /pgf/number format/.cd, fixed, fixed zerofill},
    scaled ticks=false,
    yticklabel style={/pgf/number format/precision=2}, 
    xticklabel style={/pgf/number format/precision=3},             ]
%legend
    \legend{6.564x}
%linear line
\addplot [domain=0:0.022, samples=2,color=blue]   {6.564*x};
%data points
\addplot +[only marks, mark=oplus, color=black] coordinates
      {(.0077,.05) (.0107 ,.07) (.0136,.09) (.0167,.11) (.0196,.13)};
\end{axis}
    \end{tikzpicture}
\end{document}

生产:

在此处输入图片描述

编辑:按照您在评论中询问的方式进行了更正。

相关内容