TiKZ Question on Plotting a Parabola

  • Context:
  • Thread starter Thread starter Ackbach
  • Start date Start date
  • Tags Tags
    Parabola Plotting
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
5 replies · 4K views
Ackbach
Gold Member
MHB
Messages
4,148
Reaction score
94
I want to plot an hormetic curve. This is the code I have so far:

Code:
\begin{tikzpicture}[scale = 0.75]
%preamble \usepackage{pgfplots}
\begin{axis}
[xlabel=Exposure,
ylabel=Benefit]
\end{axis}
\draw[black, line width = 0.50mm]   plot[smooth,domain=0:6] (\x, {4-(\x-3)^2});
\end{tikzpicture}

producing

\begin{tikzpicture}[scale = 0.75]
%preamble \usepackage{pgfplots}
\begin{axis}
[xlabel=Exposure,
ylabel=Benefit]
\end{axis}
\draw[black, line width = 0.50mm] plot[smooth,domain=0:6] (\x, {4-(\x-3)^2});
\end{tikzpicture}

Now I want the following changes:
  1. The box encloses the entire plot.
  2. There is no scale on the horizontal axis. I know! Most plots should have them, but there are specific reasons this one should not.
  3. Instead of numbers on the vertical axis, I want one tick mark above $y=0$ denoted "Good", the zero mark denoted "Neutral", and one tick mark below $y=0$ to denote "Bad".
  4. Also having some issues centering this figure, even when put into a
    Code:
    center
    environment.

One note about the function $y=4-(x-3)^2$ used in this hormetic curve: most hormetic curves go through the origin. However, this particular curve needs to go below the origin.

Thanks for your help!
 
Physics news on Phys.org
I prefer vanilla TikZ (no pgfplots).

\begin{tikzpicture}[framed,>=stealth']
%preamble \usetikzlibrary{arrows,backgrounds}
\draw[->] (0,0) -- (7,0) node[below] {Exposure};
\draw[->] (0,-6) -- (0,5) node
{Benefit};
\draw[thick] (0,-5) parabola bend (3,4) (6,-5);
\draw (3pt,2cm) -- (-3pt,2cm) node
{Good};
\node
at (-3pt,0cm) {Neutral};
\draw (3pt,-2cm) -- (-3pt,-2cm) node
{Bad};
\end{tikzpicture}

Edit: https://driven2services.com/staging/mh/index.php?threads/19543/ about TikZ should probably be made sticky in the LaTeX forum. I had to use Google to find how to customize the preamble.​
 
Evgeny.Makarov said:
I prefer vanilla TikZ (no pgfplots).

\begin{tikzpicture}[framed,>=stealth']
%preamble \usetikzlibrary{arrows,backgrounds}
\draw[->] (0,0) -- (7,0) node[below] {Exposure};
\draw[->] (0,-6) -- (0,5) node
{Benefit};
\draw[thick] (0,-5) parabola bend (3,4) (6,-5);
\draw (3pt,2cm) -- (-3pt,2cm) node
{Good};
\node
at (-3pt,0cm) {Neutral};
\draw (3pt,-2cm) -- (-3pt,-2cm) node
{Bad};
\end{tikzpicture}

Edit: https://driven2services.com/staging/mh/index.php?threads/19543/ about TikZ should probably be made sticky in the LaTeX forum. I had to use Google to find how to customize the preamble.​


Wonderful! Thanks, Evgeny. One thing, though: How do I get it to be centered? A basic center environment doesn't seem to be doing the trick.​
 
Ackbach said:
How do I get it to be centered? A basic center environment doesn't seem to be doing the trick.
On the forum or in a LaTeX document? In the latter case the [m]center[/m] environment works for me. With the following code the boxed picture is horizontally centered relative to horizontal lines across the page.

[latexs]
\hrule
\vskip 1cm

\begin{center}
\begin{tikzpicture}[>=stealth',framed]
...
\end{tikzpicture}
\end{center}

\vskip 1cm
\hrule
[/latexs]
 
Evgeny.Makarov said:
On the forum or in a LaTeX document? In the latter case the [m]center[/m] environment works for me. With the following code the boxed picture is horizontally centered relative to horizontal lines across the page.

[latexs]
\hrule
\vskip 1cm

\begin{center}
\begin{tikzpicture}[>=stealth',framed]
...
\end{tikzpicture}
\end{center}

\vskip 1cm
\hrule
[/latexs]

I have it! Your post gave me the idea of nesting the center environment inside the figure environment, instead of the other way around. That did the trick. Why this should matter is beyond me, but whatever.

Thanks for your help!
 
The [m]figure[/m] environment allocates the whole width of the page (or column), and it is usually moved away from the neighboring text in the source code. So if [m]figure[/m] is located inside [m]center[/m], the latter has no effect. If [m]center[/m] is located inside [m]figure[/m], it works as expected: first a full-width portion of a page is allocated somewhere, and then inside it centering is used.