How can I get the bounding box coordinates for the pgfplot below? I need the coordiates in pgfplot space. (current axis.south west) and (current bounding box.south west), for example, do not give what I need. I'm expecting something like SW = (-7,-1.1), NE = (8.2,1.4), which would extend to the right beyond the red rectangle.
\documentclass[border=0pt,multi=my]{standalone}
\usepackage{amssymb,amsmath}
\usepackage[pass,paperheight=\maxdimen]{geometry}
\usepackage{graphicx}
\usepackage{epsfig}
\usepackage{xcolor}
\usepackage{pgf,tikz,pgfplots}
\usetikzlibrary{calc,shapes,positioning,fit,decorations,decorations.text,decorations.pathmorphing,backgrounds,patterns,arrows,arrows.meta}
\usepackage{ifthen}
\usepackage{pagecolor}
\tikzset{every picture/.style={line width=0.02cm}}
\begin{document}
\pagestyle{empty}
\begin{my}
\begin{tikzpicture}[tight background,background rectangle/.style={draw=none,fill=red!45},show background rectangle,scale=0.85]
\begin{axis}[
name=foo,
width=360pt,
height=210pt,
xmin=-7,
xmax=8,
ymin=-1.1,
ymax=1.4,
xtick={0},
xticklabels={$0$},
ytick={0},
yticklabels={$0$},
extra x ticks={-6.283185307,-4.71238898,-3.141592654,-1.570796327,0,1.570796327,3.141592654,4.71238898,6.283185307},
extra x tick labels={$-2\pi$,$-\frac{3\pi}{2}$,$-\pi$,$-\frac{\pi}{2}$,$0$,$\frac{\pi}{2}$,$\pi$,$\frac{3\pi}{2}$,$2\pi$},
extra x tick style={
xticklabel style={below right},
},
extra y ticks={-1,1},
extra y tick labels={$-1$,$1$},
extra y tick style={
yticklabel style={right,xshift=5pt},
},
axis x line=center,
axis y line=center]
\addplot[line width=0.0325cm, cyan!60!black, domain=-7:7, samples=200] {sin(deg(x))};
\node at (axis cs:8.1,-0.12) {$x$};
\node[anchor=west] at (axis cs:0.1,1.3) {$y$};
\end{axis}
\end{tikzpicture}
\end{my}
\end{document}
It sounds as if you are looking for \pgfplotspointgetnormalizedcoordinates{}
\documentclass[border=0pt,multi=my]{standalone}
\usepackage{amssymb,amsmath}
\usepackage[pass,paperheight=\maxdimen]{geometry}
\usepackage{graphicx}
\usepackage{epsfig}
\usepackage{xcolor}
\usepackage{pgf,tikz,pgfplots}
\usetikzlibrary{calc,shapes,positioning,fit,decorations,decorations.text,decorations.pathmorphing,backgrounds,patterns,arrows,arrows.meta}
\usepackage{ifthen}
\usepackage{pagecolor}
\tikzset{every picture/.style={line width=0.02cm}}
\begin{document}
\pagestyle{empty}
\begin{my}%
\begin{tikzpicture}[tight background,background rectangle/.style={draw=none,fill=red!45},show background rectangle,scale=0.85]
\begin{axis}[
name=foo,
width=360pt,
height=210pt,
xmin=-7,
xmax=8,
ymin=-1.1,
ymax=1.4,
xtick={0},
xticklabels={$0$},
ytick={0},
yticklabels={$0$},
extra x ticks={-6.283185307,-4.71238898,-3.141592654,-1.570796327,0,1.570796327,3.141592654,4.71238898,6.283185307},
extra x tick labels={$-2\pi$,$-\frac{3\pi}{2}$,$-\pi$,$-\frac{\pi}{2}$,$0$,$\frac{\pi}{2}$,$\pi$,$\frac{3\pi}{2}$,$2\pi$},
extra x tick style={
xticklabel style={below right},
},
extra y ticks={-1,1},
extra y tick labels={$-1$,$1$},
extra y tick style={
yticklabel style={right,xshift=5pt},
},
axis x line=center,
axis y line=center]
\addplot[line width=0.0325cm, cyan!60!black, domain=-7:7, samples=200] {sin(deg(x))};
\node (myx) at (axis cs:8.1,-0.12) {$x$};
\node[anchor=west] at (axis cs:0.1,1.3) {$y$};
\node[green] at (200,10) {
\pgfplotspointgetnormalizedcoordinates{(xticklabel cs:0)}
\pgfmathprintnumber{\pgfkeysvalueof{/data point/x}}
\pgfplotspointgetnormalizedcoordinates{(myx.east)}
\pgfmathprintnumber{\pgfkeysvalueof{/data point/x}}
\pgfplotspointgetnormalizedcoordinates{(yticklabel cs:0)}
\pgfmathprintnumber{\pgfkeysvalueof{/data point/y}}
\pgfplotspointgetnormalizedcoordinates{(yticklabel cs:1)}
\pgfmathprintnumber{\pgfkeysvalueof{/data point/y}}
};
\draw[green, ultra thick] (axis cs:-7,-1.1) rectangle (axis cs:8.41,1.4);
\end{axis}
\end{tikzpicture}%
\end{my}%
\end{document}
Related
In the following plot, I am getting a warning. I know it has to do something with the coordinates but can't solve it for sure. If anyone can guide me in the right direction, it would be really helpful.
Package pgf Warning: No path specified that can be filled on input
line 55.
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usepackage{float}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\title{StackExchange}
\author{M. Tahasanul Ibrahim}
\date{January 2022}
\begin{document}
\begin{figure}[H]
\centering
\begin{tikzpicture}
\begin{axis}
[
% ybar,
% xmin=-1,xmax=10,
% ymin=0,ymax=18,
% xlabel={Data Value},
% ylabel={Occurrence/Frequency}]
xlabel= {Data Value},
ylabel= {Occurrence/Frequency},
enlarge x limits=0.1,
legend style={
at={(0.5,-0.15)},
anchor=north,legend columns=-1
},
width=12.8cm,
height=8cm,
point meta={x*100},
symbolic x coords={0,1,2,3,4,5,6,7,8,9},
grid=both,
grid style={line width=.1pt, draw=gray!10},
major grid style={line width=.2pt,draw=gray!50},
% axis lines=middle,
minor tick num=5,
nodes near coords={$\pgfmathprintnumber{\pgfkeysvalueof{/data point/y}}$},
]
\addplot+ [color=black, bottom color=green, top color=red] coordinates
{
(0,1)
(1,5)
(2,7)
(3,12)
(4,15)
(5,9)
(6,7)
(7,3)
(8,0)
(9,1)
} \closedcycle;
\end{axis}
\end{tikzpicture}
\caption{Area chart representing statistical data}
\end{figure}
\end{document}
These warnings arise because you are not only filling this path, you are also drawing the markers and the label markers in the same step.
If you decompose this into two separate steps, you can avoid the warnings:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usepackage{float}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\title{StackExchange}
\author{M. Tahasanul Ibrahim}
\date{January 2022}
\begin{document}
\begin{figure}[H]
\centering
\begin{tikzpicture}
\begin{axis}
[
% ybar,
% xmin=-1,xmax=10,
% ymin=0,ymax=18,
% xlabel={Data Value},
% ylabel={Occurrence/Frequency}]
xlabel= {Data Value},
ylabel= {Occurrence/Frequency},
enlarge x limits=0.1,
legend style={
at={(0.5,-0.15)},
anchor=north,legend columns=-1
},
width=12.8cm,
height=8cm,
point meta={x*100},
symbolic x coords={0,1,2,3,4,5,6,7,8,9},
grid=both,
grid style={line width=.1pt, draw=gray!10},
major grid style={line width=.2pt,draw=gray!50},
% axis lines=middle,
minor tick num=5,
% nodes near coords={$\pgfmathprintnumber{\pgfkeysvalueof{/data point/y}}$},
]
\addplot [color=black, bottom color=green, top color=red] coordinates
{
(0,1)
(1,5)
(2,7)
(3,12)
(4,15)
(5,9)
(6,7)
(7,3)
(8,0)
(9,1)
} \closedcycle;
\addplot+[black,mark=*,nodes near coords={$\pgfmathprintnumber{\pgfkeysvalueof{/data point/y}}$},] coordinates
{
(0,1)
(1,5)
(2,7)
(3,12)
(4,15)
(5,9)
(6,7)
(7,3)
(8,0)
(9,1)
};
\end{axis}
\end{tikzpicture}
\caption{Area chart representing statistical data}
\end{figure}
\end{document}
For the following
\node (formula) [] {$2x+3y$};
\draw[-latex,red] ($(formula.north west)$) arc
How could I extract the x coordinate. That is, I'm assuming that formula.north west is in the form (x,y), how can I get the x and y coordinates separately?
I'm using \tikzmath and want to do something like
\x1 = (formula.north west).x
if that makes sense?
You can use the let operation to assign the coordinate to a point register:
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
\node (formula) [] {$2x+3y$};
\draw[red] let \p1 = (formula.north west)
in (\x1,\y1) circle [radius=0.1];
\end{tikzpicture}
\end{document}
How to draw this graph in LaTeX? I have used TikZ but I can't get it done exactly.
This is what I have tried so far:
\begin{tikzpicture}
\tkzInit[xmax=6,ymax=6,xmin=-6,ymin=-1]
\tkzAxeXY
\draw[thick] (6,3) -- (-4,5);
\filldraw[black] (6,3) circle (2pt) node[anchor=west] {A(6,3)};
\filldraw[black] (-4,5) circle (2pt) node[anchor=east] {B(-4,5)};
\end{tikzpicture}
Using regular pgfplots you could do the following: Draw the line with the points you choose and label them with nodes. Then draw the additional distance markers using \draw in the axis coordinate system (The concrete positions of all elements may have to be adjusted).
\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\tiny
\begin{axis}[
width = 6cm,
height = 4cm,
ymajorgrids = true,
ymin=-1,
ymax=7,
xmin=-6,
xmax=6,
xtick distance=1,
ytick distance=1,
axis y line*=center,
axis x line*=center,
enlarge x limits=.12
]
\addplot+[sharp plot] coordinates {(6,3) (1,4) (-4,5) } node[below=1mm, pos=0] {A(6,3)}
node[pos=0.45,below=1mm] {P(x,y)}
node[pos=1,below=1mm] {B(-4,5)};
\draw[|-|] (axis cs:1.2,5) -- node [above, rotate=-10] {m=13} (axis cs:6.3,3.9);
\draw[|-|] (axis cs:-3.8,6) -- node [above, rotate=-10, pos=.3] {n=2} (axis cs:1.2,5);
\end{axis}
\end{tikzpicture}
\end{document}
Output:
I am trying to make a stacked barplot aligned to the y-axis of the tikzpicture.
\begin{tikzpicture}
\begin{axis}[
ybar stacked,
bar width=15pt,
ymin=29,
nodes near coords,
enlargelimits=0.15,
legend style={at={(0.5,-0.15)},
anchor=north,legend columns=-1},
ylabel={Seconds (s)},
symbolic x coords={t1, t2, t3, t4},
xtick=data,
x tick label style={rotate=45,anchor=east},
]
\addplot+[ybar] plot coordinates {(t1, 143) (t2, 203) (t3, 174) (t4, 188)};
\addplot+[ybar] plot coordinates {(t1, 34) (t2, 36) (t3, 39) (t4, 35)};
\legend{\strut S1,\strut S2}
\end{axis}
\end{tikzpicture}
As seen, I have used ymin to force it being close to the y-axis but it does not look perfect. Also, I want to be able to automate this since I have a lot of figures that needs this configuration and doing it manually takes time.
With ymin=0 and without additional enlarging of this limit:
\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
ybar stacked,
bar width=15pt,
ymin=0,
nodes near coords,
% enlargelimits=0.15,
legend style={at={(0.5,-0.15)},
anchor=north,legend columns=-1},
ylabel={Seconds (s)},
symbolic x coords={t1, t2, t3, t4},
xtick=data,
x tick label style={rotate=45,anchor=east},
]
\addplot+[ybar] plot coordinates {(t1, 143) (t2, 203) (t3, 174) (t4, 188)};
\addplot+[ybar] plot coordinates {(t1, 34) (t2, 36) (t3, 39) (t4, 35)};
\legend{\strut S1,\strut S2}
\end{axis}
\end{tikzpicture}
\end{document}
I have loglog axis in Latex and i want to change scaling of the y-Axis like this: y-Axis should be signed with: 5*10e1, 10e2, 2*10e2 But this numbers should be shown in integer like: 50, 100, 200. The gird of the diagramm should be stay the same.
\documentclass[12pt]{scrartcl}
\usepackage[paperwidth=18cm, paperheight=12cm]{geometry}
%Digrammzeug
\usepackage{pgfplots}
\begin{document}
\thispagestyle{empty} % um die Seitenzahl zu endfernen
\newgeometry{left=0.1cm, right=0.1cm, top=0.1cm, bottom=0.1cm}
\begin{figure}
\centering
\begin{tikzpicture}
\begin{loglogaxis}[
axis x line=bottom,
axis y line=left,
ymax = 2.1*10^2,
xlabel=N (log),
ylabel=$ \mathrm{S_a} $ in MPa (log),
every axis x label/.style={
at={(ticklabel* cs:1.05)},
anchor=west,
},
every axis y label/.style={
at={(ticklabel* cs:1.05)},
anchor=south,
},
ytick={10, 100},
scale=1.6,
grid=both,
tick align=outside,
tickpos=left,
]
%Lasth 1
\node at (axis cs: 10^5.25,10^2.193) {Lasthorizont I};
%Lasth 2
\node at (axis cs: 10^6.2,10^1.955) {Lasthorizont II};
%Lasth 1 - 2 Gerade
\addplot[black, mark=square*] coordinates { (50966, 155.74) (477468, 90.16)};
%Lasth 2 - N_D Gerade
\addplot[black,no marks] coordinates { (477468, 90.16) (2.5*10^6, 60.16677272)};
%Dauerfestigkeit
\addplot[black, mark=square*, mark indices={1}] coordinates { (2.5*10^6, 60.16677272) (10^7, 60.16677272)};
\addplot[black, dotted, no marks] coordinates { (2.5*10^6, 60.16677272) (10^7.3, 60.16677272) };
\addplot[black, dashed] coordinates { (10^4, 60.16677272) (2.5*10^6, 60.16677272) };
%Beschriftung
\addplot[dashed] coordinates { (2.5*10^6, 60.16677272) (2.5*10^6, 10^1.7)};
\node at (axis cs: 10^5.4,10^1.85) {Zeitfestigkeit};
\node at (axis cs: 10^5.4,10^1.74) {Dauerfestigkeit};
\node at (axis cs: 10^6.85,10^1.73) {$ N_D=2,5\cdot10^6 $};
\node at (axis cs: 10^4.4,10^1.Cool {$ S_{aD} \approx $ 60.17};
%Lasthorizont III
\addplot[black, thick, mark=x] coordinates {(180000, 117.49)};
\node at (axis cs: 10^5.8, 10^2.07) {Lasthorizont III};
\end{loglogaxis}
\end{tikzpicture}
\end{figure}
\end{document}
I realize this question has been asked long ago, and belongs on tex.stackexchange.com, but for those who are looking for a solution and find this question without an answer; I've found a working solution which I will share below.
I found the answer to your question in #Jake's one and two answers.
What you're looking for (I think) is a combination of the axis environment with xmode=log and ymode=log. In order to get the axis labeled you combine it with log ticks with fixed point. This is a default pgf option which will modify both axis.
Since you're asking for only specific y-axis ticks I use this for the working example below using a new definition of a pgfplotsset. By the way, I commented the line with .Cool since I'm not familiar with this and it causes problems with me, feel free to un-comment it.
\begin{tikzpicture}
\pgfplotsset{
log x ticks with fixed point/.style={
xticklabel={
\pgfkeys{/pgf/fpu=true}
\pgfmathparse{exp(\tick)}%
\pgfmathprintnumber[fixed relative, precision=3]{\pgfmathresult}
\pgfkeys{/pgf/fpu=false}
}
},
log y ticks with fixed point/.style={
yticklabel={
\pgfkeys{/pgf/fpu=true}
\pgfmathparse{exp(\tick)}%
\pgfmathprintnumber[fixed relative, precision=3]{\pgfmathresult}
\pgfkeys{/pgf/fpu=false}
}
}
}
\begin{axis}
[xmode=log,
ymode=log,
log x ticks with fixed point,
axis x line=bottom,
axis y line=left,
ymax = 2.1*10^2,
xlabel=N (log),
ylabel=$ \mathrm{S_a} $ in MPa (log),
every axis x label/.style={
at={(ticklabel* cs:1.05)},
anchor=west,
},
every axis y label/.style={
at={(ticklabel* cs:1.05)},
anchor=south,
},
ytick={10, 100},
scale=1.6,
grid=both,
tick align=outside,
tickpos=left,
]
%Lasth 1
\node at (axis cs: 10^5.25,10^2.193) {Lasthorizont I};
%Lasth 2
\node at (axis cs: 10^6.2,10^1.955) {Lasthorizont II};
%Lasth 1 - 2 Gerade
\addplot[black, mark=square*] coordinates { (50966, 155.74) (477468, 90.16)};
%Lasth 2 - N_D Gerade
\addplot[black,no marks] coordinates { (477468, 90.16) (2.5*10^6, 60.16677272)};
%Dauerfestigkeit
\addplot[black, mark=square*, mark indices={1}] coordinates { (2.5*10^6, 60.16677272) (10^7, 60.16677272)};
\addplot[black, dotted, no marks] coordinates { (2.5*10^6, 60.16677272) (10^7.3, 60.16677272) };
\addplot[black, dashed] coordinates { (10^4, 60.16677272) (2.5*10^6, 60.16677272) };
%Beschriftung
\addplot[dashed] coordinates { (2.5*10^6, 60.16677272) (2.5*10^6, 10^1.7)};
\node at (axis cs: 10^5.4,10^1.85) {Zeitfestigkeit};
\node at (axis cs: 10^5.4,10^1.74) {Dauerfestigkeit};
\node at (axis cs: 10^6.85,10^1.73) {$ N_D=2,5\cdot10^6 $};
%\node at (axis cs: 10^4.4,10^1.Cool {$ S_{aD} \approx $ 60.17};
%Lasthorizont III
\addplot[black, thick, mark=x] coordinates {(180000, 117.49)};
\node at (axis cs: 10^5.8, 10^2.07) {Lasthorizont III};
\end{axis}
\end{tikzpicture}
This provides the following figure: