MHB TiKZ Question on Plotting a Parabola

  • Thread starter Thread starter Ackbach
  • Start date Start date
  • Tags Tags
    Parabola Plotting
AI Thread Summary
The discussion revolves around plotting a hormetic curve using TikZ in LaTeX. The user initially shares code that produces a basic plot but seeks modifications, including enclosing the plot in a box, removing the horizontal axis scale, and customizing the vertical axis labels to indicate "Good," "Neutral," and "Bad" at specific points. The user also expresses a preference for using vanilla TikZ instead of pgfplots. After receiving assistance, the user encounters issues with centering the figure. The solution involves nesting the center environment within the figure environment, which resolves the centering problem. The final code successfully implements the desired plot modifications and achieves proper centering. The discussion highlights the importance of understanding LaTeX environments for effective figure placement and customization.
Ackbach
Gold Member
MHB
Messages
4,148
Reaction score
93
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.
 

Similar threads

Replies
4
Views
2K
Replies
7
Views
2K
Replies
1
Views
2K
Replies
2
Views
2K
Replies
8
Views
2K
Replies
0
Views
5K
Replies
2
Views
1K
Replies
5
Views
2K
Back
Top