如何用选定的刻度在一个轴上绘制不等式解?

如何用选定的刻度在一个轴上绘制不等式解?

我想在一个轴上绘制以下不等式的解1< x < 4. 我怎样才能通过使用 tikz 和 show仅限数字 1 和 4 的刻度

我尝试了这个:

\documentclass[a4paper,11pt]{article}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{pgfplots,tikz}
\usepackage{tkz-euclide,tkz-fct}
\begin{document}
\begin{tikzpicture}
\tkzInit[xmin=-2,xmax=5,xstep=1]
\tkzDrawX
\tkzLabelX[label options={text=black,below = 3pt}]
\tkzDefPoint(1,0){A}
\tkzDefPoint(4,0){B}
\tkzDrawSegment[line width=1mm](A,B)
\end{tikzpicture}
\end{document}

答案1

像这样吗?

\documentclass[a4paper,11pt]{article}
    \usepackage{amssymb}
    \usepackage{amsmath}
    \usepackage{pgfplots,tikz}
    \usepackage{tkz-euclide,tkz-fct}
    \begin{document}
    \begin{tikzpicture}
    \tkzInit[xmin=-2,xmax=5,xstep=1]
    \tkzDrawX
    %\tkzLabelX[label options={text=black,below = 3pt}]
    \tkzDefPoint(1,0){A}
    \tkzDefPoint(4,0){B}
    \tkzDrawSegment[line width=1mm](A,B)
    \node at (1,0) [below=1mm] {$1$};
    \node at (4,0) [below=1mm] {$4$};
    \end{tikzpicture}
    \end{document}

在此处输入图片描述

或者仅使用 TiKz:

\documentclass[a4paper,11pt]{article}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{pgfplots,tikz}
\pgfplotsset{compat=1.9}
\begin{document}
\begin{tikzpicture}
\draw[-latex] (-2,0) -- (5.5,0)node[below]{$x$};
\draw [line width=0.75mm] (1,0)--(4,0);
\foreach \x in {1,4}
            \draw (\x,3pt) -- (\x,-3pt)
            node[anchor=north] {\x};
\end{tikzpicture}
\end{document}

在此处输入图片描述

答案2

我今天遇到了同样的问题。所以我从@ferahfeza 的代码开始(非常感谢 ;) )并修改了他的代码。

\documentclass[a4paper,11pt]{article}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{pgfplots,tikz}
\pgfplotsset{compat=1.9}
\begin{document}
\begin{tikzpicture}
%x coordinate of start and end point of interval interval 1
\def \Xa {1}
\def \Xb {4}



\def \XStart {-2}
\def \XEnd {5.5}

%coordinates of start and end point of interval
\coordinate (A) at (\Xa,0);
\coordinate (B) at (\Xb,0);

%coordinates of start and end point of x-axis
\coordinate (START) at (\XStart,0);
\coordinate (END) at (\XEnd,0);

\draw[-latex,line width=0.25mm] (START) -- (END)node[below]{$x$};
%draw interval
\draw [line width=0.95mm] (A)--(B);
\foreach \x in {\Xa,\Xb}
        \draw (\x,4pt) -- (\x,-4pt)
        node[anchor=north] {\x};
%open dot in A         
\draw [color=black,line width=0.25mm,fill=white,fill opacity=1.0] (\Xa,0) circle             (0.15cm);
%open dot in B    
\draw [color=black,line width=0.25mm,fill=white,fill opacity=1.0] (\Xb,0) circle     (0.15cm);


\draw node[above left] at (\XEnd,-2) {$1 < x < 4$};            
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容