如何在 tikzpicture 图中显示原点 $O$

如何在 tikzpicture 图中显示原点 $O$

这可能是一个愚蠢的问题,但是如何修改下面的代码来显示原点 $O$ 而不改变 xmin 和 ymin 值?

以下是代码生成的图表。

图形

\documentclass[]{article}
\usepackage[margin=0.5in]{geometry}
\usepackage{pgfplots}
\renewcommand{\thesection}{\arabic{section}}
\usepackage{mathtools}
\usepackage{cancel}
\usepackage{pgfplots}
\usepackage{amsmath}
\setlength\parskip{0pt}
\begin{center}}{\end{center}}
\begin{document}
\textbf{Question 3} (10 marks)\\[0.124cm]
\begin{center}
\begin{tikzpicture}[scale=0.8]
\begin{axis}[
axis lines=middle,
grid=major,
minor tick num=4,
grid=both,
grid style={line width=.1pt, draw=gray!30},
major grid style={line width=.2pt,draw=gray!50},
xmin=0,
xmax=61,
ymin=0,
ymax=122,
height=14cm,
width=15cm,
xlabel=$\textit{Time (minutes)}$,
ylabel=$\textit{Cumulative Frequency}$,
xtick={0,5,10,15,20,25,30,35,40,45,50,55,60},
%symbolic x coords={0,5,10,15,20,25,30,35,40,45,50,55,60},
ytick={0,10,20,30,40,50,60,70,80,90,100,110,120},
%ylabel=\textit{distance}\text{ (cm)},
ylabel style={
anchor=south,
at={(ticklabel* cs:1.0)},
yshift=5pt
},
xlabel style={
anchor=west,
at={(ticklabel* cs:1.0)},
xshift=5pt
},
%xlabel=\textit{t}\text{ (s)},
%yticklabel style={
%fill=white,
%yshift=10pt,
%},
%xticklabel style={
%xshift=10pt,
%fill=white
%},
]
\draw [thick] (axis cs:5,0) edge[bend right=30] (axis cs:40,60);
\draw [thick] (axis cs:40,60) edge[bend left=10] (axis cs:60,120);
%
\node [below] at (axis cs:-1,0) {$O$};
\end{axis}
\newline
\end{tikzpicture}
\end{center}
\end{document}

答案1

你可以只取一个节点。(你只需要确保不要把它剪掉。)

\documentclass[]{article}
\usepackage[margin=0.5in]{geometry}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\usepackage{amsmath}
\setlength\parskip{0pt}
\begin{document}
\textbf{Question 3} (10 marks)\\[0.124cm]
\begin{center}
\begin{tikzpicture}[scale=0.8]
\begin{axis}[
axis lines=middle,
grid=major,
minor tick num=4,
grid=both,
grid style={line width=.1pt, draw=gray!30},
major grid style={line width=.2pt,draw=gray!50},
xmin=0,
xmax=61,
ymin=0,
ymax=122,
height=14cm,
width=15cm,
xlabel=$\textit{Time (minutes)}$,
ylabel=$\textit{Cumulative Frequency}$,
xtick={0,5,10,15,20,25,30,35,40,45,50,55,60},
%symbolic x coords={0,5,10,15,20,25,30,35,40,45,50,55,60},
ytick={0,10,20,30,40,50,60,70,80,90,100,110,120},
clip=false
%ylabel=\textit{distance}\text{ (cm)},
% ylabel style={
% anchor=south,
% at={(ticklabel* cs:1.0)},
% yshift=5pt
% },
% xlabel style={
% anchor=west,
% at={(ticklabel* cs:1.0)},
% xshift=5pt
% },
%xlabel=\textit{t}\text{ (s)},
%yticklabel style={
%fill=white,
%yshift=10pt,
%},
%xticklabel style={
%xshift=10pt,
%fill=white
%},
]
\draw [thick] (axis cs:5,0) edge[bend right=30] (axis cs:40,60);
\draw [thick] (axis cs:40,60) edge[bend left=10] (axis cs:60,120);
%
\node [anchor=north] at (axis cs:0,0) {$O$};
\end{axis}
\end{tikzpicture}
\end{center}
\end{document}

在此处输入图片描述

如果你不想删除剪辑,你可以这样做

\documentclass[]{article}
\usepackage[margin=0.5in]{geometry}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\usepackage{amsmath}
\setlength\parskip{0pt}
\begin{document}
\textbf{Question 3} (10 marks)\\[0.124cm]
\begin{center}
\begin{tikzpicture}[scale=0.8]
\begin{axis}[
axis lines=middle,
grid=major,
minor tick num=4,
grid=both,
grid style={line width=.1pt, draw=gray!30},
major grid style={line width=.2pt,draw=gray!50},
xmin=0,
xmax=61,
ymin=0,
ymax=122,
height=14cm,
width=15cm,
xlabel=$\textit{Time (minutes)}$,
ylabel=$\textit{Cumulative Frequency}$,
xtick={0,5,10,15,20,25,30,35,40,45,50,55,60},
%symbolic x coords={0,5,10,15,20,25,30,35,40,45,50,55,60},
ytick={0,10,20,30,40,50,60,70,80,90,100,110,120},
%ylabel=\textit{distance}\text{ (cm)},
% ylabel style={
% anchor=south,
% at={(ticklabel* cs:1.0)},
% yshift=5pt
% },
% xlabel style={
% anchor=west,
% at={(ticklabel* cs:1.0)},
% xshift=5pt
% },
%xlabel=\textit{t}\text{ (s)},
%yticklabel style={
%fill=white,
%yshift=10pt,
%},
%xticklabel style={
%xshift=10pt,
%fill=white
%},
]
\draw [thick] (axis cs:5,0) edge[bend right=30] (axis cs:40,60);
\draw [thick] (axis cs:40,60) edge[bend left=10] (axis cs:60,120);
%
\end{axis}
\node [anchor=north] at (0,0) {$O$};
\end{tikzpicture}
\end{center}
\end{document}

但请注意,这在这里有点偶然。您也可以尝试在环境\coordinate (O) at (axis cs:0,0);内添加命名坐标axis,然后使用 在外部绘制节点\node [anchor=north] at (O) {$O$};。但是,我在尝试时遇到了一些小变化。这与讨论的内容是否有任何关系这里, 我不知道。

相关内容