Tizk,数据可视化:轴样式和虚线端

Tizk,数据可视化:轴样式和虚线端

很抱歉打扰您回答另一个问题,但我喜欢学习这些东西。我正在学习数据可视化、Tikz/LaTeX,作为尝试,我想绘制函数 $x^2$。这是我迄今为止的工作,试图实现我想要的图片风格:

\documentclass[a4paper, 14pt]{extarticle}
\usepackage{geometry}
\geometry{total={173mm, 257mm}, left=23mm, top=23mm, right=23mm, bottom=23mm}
\usepackage{amsmath}


\usepackage[bb=stixtwo]{mathalpha}

\usepackage{concmath}



\usepackage[usenames,dvipsnames]{color}
\usepackage{graphicx}

\usepackage{pstricks}
\usepackage{tikz}
\usetikzlibrary {datavisualization.formats.functions}
\usepackage{pspicture}
\usepackage{physics}
\usepackage{multicol}

\usepackage{xcolor}
\usepackage{wasysym}
\usepackage{tabularx}
\usepackage{mathtools}
\usepackage{enumerate}
\usepackage{verbatim}
\usepackage{tcolorbox}
\pagenumbering{gobble}


\begin{center}
\begin{tikzpicture}[scale=1.2]
\datavisualization [school book axes, 
every visualizer/.style={very thick},

x axis={label=$\vu*{x}$},
y axis={label=$\vu*{y}$},
visualize as smooth line
] 

data [format=function] {
 var x : interval [-2:2];
 func y = \value x*\value x + 1;
};
\end{tikzpicture}
\end{center}

\end{document}

问题:

我怎样才能加粗坐标轴?我怎样才能给曲线 $x^2$ 添加虚线末端,以显示它是一个不断延续的函数?

谢谢你!

答案1

我使用我之前的回答来提出这一点:

在此处输入图片描述

代码:

\documentclass[border=5mm]{standalone}
\usepackage{tikz}

\begin{document}
    \begin{tikzpicture}
        \draw[gray!20](-4,-4) grid (4,4); % grid
        % x & y axis plus scale
        \foreach \x in {-4,-3,-2,-1,1,2,3,4}{
            \draw (\x,.1)--(\x,-.1) node[below,fill=white]() {\footnotesize $\x$};
            \draw (.1,\x)--(-.1,\x) node[left,fill=white]() {\footnotesize $\x$};
        }
        \draw[->,line width=.5pt] (-4,0)-- (4.5,0) node[below]() {$x$};
        \draw[->,line width=.5pt] (0,-4)-- (0,4.5) node[right]() {$y$};
        \node at(.2,-.2) () {\footnotesize O};
        % function(s) to plot in the next lines
        
        \clip (-4,-4) rectangle (4,4);
        \draw[magenta,domain=-4:4,line width=2pt,smooth] plot (\x,\x*\x);
    \end{tikzpicture}
\end{document}

添加:要查看两个虚线端点,请考虑以下修改后的代码:

\documentclass[border=5mm]{standalone}
\usepackage{tikz}

\begin{document}
    \begin{tikzpicture}
        \draw[gray!20](-4,-4) grid (4,4); % grid
        % x & y axis plus scale
        \foreach \x in {-4,-3,-2,-1,1,2,3,4}{
            \draw (\x,.1)--(\x,-.1) node[below,fill=white]() {\footnotesize $\x$};
            \draw (.1,\x)--(-.1,\x) node[left,fill=white]() {\footnotesize $\x$};
        }
        \draw[->,line width=.5pt] (-4,0)-- (4.5,0) node[below]() {$x$};
        \draw[->,line width=.5pt] (0,-4)-- (0,4.5) node[right]() {$y$};
        \node at(.2,-.2) () {\footnotesize O};
        
        % function(s) to plot in the next lines
        \begin{scope}
            \clip (-4,-4) rectangle (4,4);
            \draw[magenta,domain=-4:4,line width=2pt,smooth] plot (\x,\x*\x);
        \end{scope}
        \begin{scope}
            \clip (-4,4) rectangle (4,4.5);
            \draw[magenta,domain=-4:4,line width=2pt,smooth,dotted] plot (\x,\x*\x);
        \end{scope}
    \end{tikzpicture}
\end{document}

输出: 在此处输入图片描述

相关内容