TiKZ Question on Plotting a Parabola

  • Context: MHB 
  • Thread starter Thread starter Ackbach
  • Start date Start date
  • Tags Tags
    Parabola Plotting
Click For Summary

Discussion Overview

The discussion revolves around plotting a hormetic curve using TiKZ in LaTeX. Participants explore various aspects of the code, including modifications to axis labels, tick marks, and centering the figure within a document.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Conceptual clarification

Main Points Raised

  • One participant shares initial code for plotting a hormetic curve and requests specific modifications, such as enclosing the plot, adjusting axis labels, and centering the figure.
  • Another participant suggests using vanilla TiKZ instead of pgfplots, providing an alternative code snippet that meets some of the requested modifications.
  • There is a discussion about centering the figure, with one participant expressing difficulty using the center environment and seeking clarification.
  • A later reply explains that nesting the center environment inside the figure environment resolves the centering issue, although the reasoning behind this behavior is questioned.
  • Participants discuss the implications of the figure environment's behavior on centering and layout in LaTeX documents.

Areas of Agreement / Disagreement

Participants do not reach a consensus on the best approach to plotting the curve, as different methods are proposed. There is also no agreement on the reasoning behind the centering issue, indicating a lack of resolution on that point.

Contextual Notes

Participants express uncertainty about the behavior of the center environment and the figure environment in LaTeX, highlighting potential limitations in understanding how these environments interact.

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.
 

Similar threads

  • · Replies 4 ·
Replies
4
Views
2K
Replies
5
Views
3K
  • · Replies 7 ·
Replies
7
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 0 ·
Replies
0
Views
6K
  • · Replies 2 ·
Replies
2
Views
1K
  • · Replies 5 ·
Replies
5
Views
3K