TiKZ Question on Plotting a Parabola

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

This discussion focuses on customizing a TikZ plot to represent a hormetic curve using LaTeX. The user seeks to modify the plot by enclosing it in a box, removing the horizontal axis scale, and labeling the vertical axis with "Good," "Neutral," and "Bad" instead of numerical values. Additionally, the user encounters issues with centering the figure, which is resolved by nesting the center environment within the figure environment. The final code utilizes vanilla TikZ without pgfplots.

PREREQUISITES
  • Familiarity with LaTeX document preparation.
  • Understanding of TikZ for creating graphics in LaTeX.
  • Knowledge of plotting functions and their representations.
  • Basic experience with LaTeX environments such as center and figure.
NEXT STEPS
  • Explore advanced TikZ features for custom plotting.
  • Learn about LaTeX environments and their nesting rules.
  • Investigate the use of pgfplots for enhanced plotting capabilities.
  • Study the principles of hormesis and its graphical representation.
USEFUL FOR

LaTeX users, researchers in biological sciences, and anyone interested in creating customized plots using TikZ for visualizing hormetic curves.

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