TiKZ Question on Plotting a Parabola

In summary: On the forum or in a LaTeX document? In the latter case the center environment works for me. With the following code the boxed picture is horizontally centered relative to horizontal lines across the page.
  • #1
Ackbach
Gold Member
MHB
4,155
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
  • #2
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.​
 
  • #3
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.​
 
  • #4
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]
 
  • #5
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!
 
  • #6
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.
 

FAQ: TiKZ Question on Plotting a Parabola

How do I plot a parabola with TiKZ?

To plot a parabola using TiKZ, you can use the \draw command followed by the parabola equation. For example, to plot the parabola y = x^2, you would use \draw plot (\x, \x^2); in your TiKZ environment.

Can I customize the appearance of my parabola plot in TiKZ?

Yes, you can customize the appearance of your parabola plot in TiKZ by adding options to the \draw command. Some options you can use include color, thick, and domain to change the color, thickness, and domain of the parabola plot, respectively.

How do I label the axes and add a title to my parabola plot in TiKZ?

To label the axes, you can use the \draw command followed by the axis option and specify the labels for the x-axis and y-axis. To add a title, you can use the \node command and specify the title text inside the curly braces. For example, \node at (current bounding box.north) [above=1cm] {Parabola Plot}; will add a title above the plot.

Is it possible to plot multiple parabolas on the same graph using TiKZ?

Yes, you can plot multiple parabolas on the same graph using TiKZ by using multiple \draw commands with different equations. You can also use different options for each parabola to differentiate them, such as using different colors or line styles.

Can I use TiKZ to add annotations or points of interest to my parabola plot?

Yes, you can use TiKZ to add annotations or points of interest to your parabola plot. You can use the \node command to add text or labels at specific coordinates on the plot. You can also use the \draw command to add additional elements, such as points or lines, to the plot.

Similar threads

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