1

I want to graph 8 inequalities and a number line, like I show below:

enter image description here

Note that it's different from plotting the inequalities themself, like it would be plotting x<2 for a x-number line (that is, it's redundant to have the inequality expression itself in the graph). In my case, for a specific range of my number line variable multiple inequalities may hold. Perhaps the closest question to mine is: Graphing a non-linear inequality? (see highest score answer).

Required specifications:

  1. Horizontal layout: I need my graph to be in horizontal layout and occupy the whole page so that it's better readable (since I need to fit the inequality themself in the graph);
  2. Number line at the bottom: I need the 8 inequalities to be above the number line, not some above and some below;
  3. Clarity: I need to display the 8 inequalities in the clearest way possible (is what I show in the picture the clearest way in my case or something like the output in Graphing a non-linear inequality? would be better? If the latter is more clear, how to adapt the script to my case? Perhaps you can show me a MWE with 3 or 4 inequalities).

MWE (sorry for the bad formatting):

\documentclass[tikz,border=5mm]{standalone}
\usepackage{tikz}
\usepackage{amssymb}
\usetikzlibrary{plotmarks}

\begin{document}

%--------------------------------------------------------- \begin{tikzpicture} \coordinate (A) at (3,0); \coordinate (B) at (7,0); \coordinate (LE) at (0,0);

    \draw[-&gt;, line width=0.1mm] (0,0) -- (10,0) ;
    \path node[mark size=3pt,color=black] at (A) {\pgfuseplotmark{*}} node at (A) [below=5pt] {$\sigma_d$} node[mark size=3pt,color=black] at (B) {\pgfuseplotmark{*}} node at (B) [below=5pt] {$\sqrt{2}\sigma_d$};
    \draw[-&gt;, line width=0.5mm] ([yshift=1cm]A) -- node[above] {$\partial f/\partial x$}([yshift=1cm]LE);
    \draw[-&gt;, line width=0.5mm] ([yshift=2cm]B) -- node[above] {$\partial f/\partial y$}([yshift=2cm]LE);
\end{tikzpicture}

%---------------------------------------------------------

\end{document}

The above produces: enter image description here

Questions:

  1. Is it better to have my inequalities on top of the arrows themselves (like in this MWE) or on the right side of the number line, stacked on top of each other like in the solution from my link above?
  2. Is it better to have multiple inequalities on a single arrow (to reduce the number of arrows since some of them hold for the same range) or is it better to have one arrow for each inequality like in the picture I posted?
  3. How to add the variable name "sigma_v" at the right end of the number line?

Thanks a lot!

MS-SPO
  • 11,519
  • Welcome. // I suggest using Tikz, with documentclass standalone, and including the pdf via package graphicx in your main document. The lines are easy enough with Tikz, the math goes into nodes you place. // I suggest to add even a rudimentary Tikz trial with your question (via EDIT). The Tikz code will be simpler than the solutions from your link. – MS-SPO Mar 18 '24 at 04:56
  • I suggest using Inkscape. You can draw the image in WYSIWYG mode and export it to a pdf file with the text exported separately to a TeX file. Then you can use \inkinspic macro to load the image with text together in OpTeX or some similar in LaTeX. – wipet Mar 18 '24 at 06:30
  • @MS-SPO please check my MWE. Thanks a lot to wipet for the suggestion too, but I think MS-SPO's implementation would be simpler. – anonymous Mar 18 '24 at 07:12

1 Answers1

0

I must admit you made a pretty good start for a beginner in Tikz.

There is always more than one way to do such drawings. Here I show you some alternatives, which also guides you through some nice Tikz-features, to keep you moving fast.

Self-defined formats

Should speak for themselves. You just introduce, use and modify them as you go, often later than too early. E.g. you may find that you use the same options, so you'd refactor them, i.e. make them a style and use it.

Axis

Can be done directly. Some people favor relative placements, or tikzlibrary positioning. However, this diagram is simple and clear enough to use absolute (manually scaled) coordinates.

First path:

  • recall, syntactically Tikz starts a path with \ and ends it with ;
  • everything in between is action (like in a movie scene)
  • so draw
  • to two points, where the 2nd is specified in relative terms
  • before you're done put a node
  • anchor it west (i.e. so you have tip.east matches node.west in pseudocode)

The second path is similar, besides you repeat draw's several times to tick the axis. You can use other units of length, too, e.g. mm.

    % ~~~ horizontal axis with tiks ~~~~~
    %     changed from width 6 to 12 to "uncrowd" the labels
    \draw[->] (0,0) -- +(12,0) node[anchor=west]{$\sigma_v$};
    %     to replicate your sketch
    \foreach \t in {1,2,3,4, 4.5, 5}
        \draw (2*\t,0) -- +(0,2pt) -- +(0,-2pt);

Axis labels

You simply place nodes. If you give them different names, like X4, life will be easier a few pathes ahead.

    % ~~~ axis labels: though this step could be looped,
    %     I think it results in more readable code this way
    \node[lbl]      at (2,0) {$\sigma_d$};
    \node[lbl] (X4) at (8,0) {$\frac{\sqrt{10}}{2}\sigma_d$};

Your arrows with inequalitites

I show you two approaches.

In the first one this happens:

  • you draw a line, just like with the axis
  • to make it meander you say: (up |) (side -) or |-
  • before the path ends you put a node for the inequalities text
  • you shift it along that meandering path using pos
  • this is trial and error by its very nature
  • anchor it south, so it will be above the horizontal part
    \draw[->] (6,0) |- (0,5) 
        % ~~~ trial and error wrt pos ~~~~~~~~~
            node[pos=.5,anchor=south]{$\partial f/\partial x$};

The second uses an intermediate coordinate, (A2) in this case. I often find it easier to split the path to position the node:

  • path starts at A2
  • where you put a node
  • and anchor it east (i.e. at A2)
    \draw[]   (8,0) |- +(0,3) coordinate(A2);
    \draw[->] (A2) node[anchor=south east,ineq] {
                                $\partial f/\partial x$}
                    --  (0,3) ;

Downward arrows

Just for demonstration purposes: this way Tikz puts the starting point automatically.

    % ~~~ the advantage of giving the label nodes a name ~~~
    \draw[->] (X4) -- +(0,-1);

Legibility

Where you put the inequalities is up to you. Oftentimes once you created a little graphical mess it reveals more easily, where and how you should place them: there can be differences. E.g. some labels can be along the line, while others have a better (i.e. more meaningful) place near the endidng arrow tip (anchor=east).

One example I showed adding some backgroud fill via style ineq.

Result + code

result

\documentclass[10pt,tikz,border=5mm]{standalone} % <<<
%\usepackage{tikz}              % already loaded with class statement
\usepackage{amssymb}
\usetikzlibrary{arrows.meta}    % <<<

\begin{document}

%--------------------------------------------------------- \begin{tikzpicture}[ % self-defined styles >={Stealth}, % change all arrow tips lbl/.style={anchor=north}, ineq/.style={fill=teal!10}, ] % ~~~ horizontal axis with tiks ~~~~~ % changed from width 6 to 12 to "uncrowd" the labels \draw[->] (0,0) -- +(12,0) node[anchor=west]{$\sigma_v$}; % to replicate your sketch \foreach \t in {1,2,3,4, 4.5, 5} \draw (2*\t,0) -- +(0,2pt) -- +(0,-2pt);

% ~~~ axis labels: though this step could be looped,
%     I think it results in more readable code this way
\node[lbl]      at (2,0) {$\sigma_d$};
\node[lbl] (X4) at (8,0) {$\frac{\sqrt{10}}{2}\sigma_d$};

% ~~~ your arrows with inequalitites ~~~~~~
\draw[-&gt;] (6,0) |- (0,5) 
    % ~~~ trial and error wrt pos ~~~~~~~~~
        node[pos=.5,anchor=south]{$\partial f/\partial x$};

%     alternative using an intermediat coordinate, split
\draw[]   (8,0) |- +(0,3) coordinate(A2);
\draw[-&gt;] (A2) node[anchor=south east,ineq] {
                            $\partial f/\partial x$}
                --  (0,3) ;

% ~~~ the advantage of giving the label nodes a name ~~~
\draw[-&gt;] (X4) -- +(0,-1);

\end{tikzpicture} \end{document}

MS-SPO
  • 11,519