Trying to create a latex column chart with single values in 3 different columns having 3 colors.
\begin{tikzpicture}
\begin{axis}[
x tick label style={
/pgf/number format/1000 sep=},
ylabel=Accuracy,
enlargelimits=0.05,
legend style={at={(0.5,-0.15)},
anchor=north,legend columns=-1},
ybar interval=0.7,]
\addplot
coordinates {(1930,80)};
\addplot
coordinates {(1930,80)};
\addplot
coordinates {(1930,80)};
\legend{Far,Near,Here}
\end{axis}
\end{tikzpicture}
You need to add a ybar size (e.g., ybar=5pt) and remove the ybar interval parameter, which looks bogus:
\begin{tikzpicture}
\begin{axis}[
ybar=5pt,
ylabel=Accuracy,
xtick=data,
legend style={at={(0.5,-0.15)}, anchor=north,legend columns=-1},
x tick label style={/pgf/number format/1000 sep=},
enlargelimits=0.05,
]
\addplot coordinates {(1930,80)};
\addplot coordinates {(1930,80)};
\addplot coordinates {(1930,80)};
\legend{Far,Near,Here}
\end{axis}
\end{tikzpicture}
Related
How can I adjust the labels on the y-axis?
In the current version, the labels are not aligned to the bars.
The example is from:
https://texample.net/tikz/examples/bar-chart/
I add a few more data fields and removed the second category.
\documentclass[border=10pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{tikzpicture}
\begin{axis}[title = Contributions per category
at LaTeX-Community.org,
xbar,
y axis line style = { opacity = 0 },
axis x line = none,
tickwidth = 0pt,
enlarge y limits = 0.2,
enlarge x limits = 0.02,
symbolic y coords = {test1,test2,test3,test4,LaTeX, Tools, Distributions, Editors},
nodes near coords,
]
\addplot coordinates { (57727,LaTeX) (5672,Tools)
(2193,Distributions) (11106,Editors)
(11106,test1)
(11106,test2)
(11106,test3)
(11106,test4)
};
\legend{Topics}
\end{axis}
\end{tikzpicture}
\end{document}
With the ytick=data option:
\documentclass[border=10pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
title = Contributions per category at LaTeX-Community.org,
xbar,
y axis line style = { opacity = 0 },
axis x line = none,
tickwidth = 0pt,
enlarge y limits = 0.2,
enlarge x limits = 0.02,
symbolic y coords = {test1,test2,test3,test4,LaTeX,Tools,Distributions,Editors},
ytick=data,
nodes near coords,
nodes near coords align={horizontal},
]
\addplot coordinates {
(57727,LaTeX)
(5672,Tools)
(2193,Distributions)
(11106,Editors)
(11106,test1)
(11106,test2)
(11106,test3)
(11106,test4)
};
\legend{Topics}
\end{axis}
\end{tikzpicture}
\end{document}
Currently I have the following figures (plots):
I have placed the pgfplots inside two subfigures such that I can add the captions. The problem however is that some white space is added on the right side of Figure 3b. I am using the \hfill option but still this white space is note removed. Does someone know how to get rid of this white space such that the righthandside of Figure 3b alligns with the borders of my paper (represented by text text text ...)
My code is as follows:
\documentclass[a4paper, 11pt]{article}
\usepackage[utf8x]{inputenc}
\usepackage[margin=2.5cm]{geometry}
\usepackage{subcaption}
\usepackage{float}
\usepackage{graphicx}
\usepackage{pgfplots}
\usepackage{tikz}
\usetikzlibrary{positioning}
\tikzset{font=\footnotesize}
\begin{document}
\begin{figure}[H]
\centering
\begin{subfigure}{0.49\textwidth}
\begin{tikzpicture}
\begin{axis}[
title={},
xlabel={Epochs},
ylabel={Rewards},
ylabel near ticks,
legend pos=south east,
ymajorgrids=true,
grid style=densely dotted,
width=7cm,
height=6cm,
legend cell align={left},
legend style={font=\footnotesize}
]
\addplot[color = black, line width = 0.25mm, mark = *, mark size = 1] coordinates {
(1, 1.5)(2, 1.3)
};
\addplot[color = black, line width = 0.25mm, mark = none, samples = 2, dashed] {1.4}; % Constant line
\legend{Plot1,}
\end{axis}
\begin{axis}[
ylabel={Percentage (\%)},
axis y line*=right,
ylabel near ticks,
ylabel style={rotate=-180},
hide x axis,
width=7cm,
height=6cm,
legend style={font=\footnotesize}
]
\addplot[color = black, mark = *, mark size = 1] coordinates {
(1, 0.5)(2, 0.6)
};
\addplot[color = black, line width = 0.25mm, mark = none, samples = 2, dashed] {0.53}; % Constant line
\legend{Plot2,}
\end{axis}
\end{tikzpicture}
\caption{Performance}
\label{Plot:}
\end{subfigure}\hfill
\begin{subfigure}{0.49\textwidth}
\begin{tikzpicture}
\begin{axis}[
title={},
xlabel={Epochs},
ylabel={Rewards},
ylabel near ticks,
legend pos=south east,
ymajorgrids=true,
grid style=densely dotted,
width=7cm,
height=6cm,
legend cell align={left},
legend style={font=\footnotesize}
]
\addplot[color = black, line width = 0.25mm, mark = *, mark size = 1] coordinates {
(1, 1.5)(2, 1.3)
};
\addplot[color = black, line width = 0.25mm, mark = none, samples = 2, dashed] {1.4}; % Constant line
\legend{Plot1,}
\end{axis}
\end{tikzpicture}
\caption{Action distribution}
\label{Plot:}
\end{subfigure}
\caption{Results}
\label{Plot:}
\end{figure}
\end{document}
The problem is that your plots are about 7 cm wide and you place them in a subfigure of .49\textwidth, so the \hfill you place between the subfigures only sees the objects of .49\textwidth and add fill space according to this. If you want to move the plot towards the right boarder, you could
a) place the \hfill into the subfigure (the caption won't be centred anymore)
b) adjust the .49\textwidth to match the actual width of the plot (something around 7 cm)
(the \fbox{...} in the code below is just to visualize the size of the plots)
\documentclass[a4paper, 11pt]{article}
\usepackage[utf8x]{inputenc}
\usepackage[margin=2.5cm,showframe]{geometry}
\usepackage{subcaption}
\usepackage{float}
\usepackage{graphicx}
\usepackage{pgfplots}
\usepackage{tikz}
\usetikzlibrary{positioning}
\tikzset{font=\footnotesize}
\begin{document}
\begin{figure}[H]
\centering
\begin{subfigure}{0.49\textwidth}
\fbox{\begin{tikzpicture}
\begin{axis}[
title={},
xlabel={Epochs},
ylabel={Rewards},
ylabel near ticks,
legend pos=south east,
ymajorgrids=true,
grid style=densely dotted,
width=7cm,
height=6cm,
legend cell align={left},
legend style={font=\footnotesize}
]
\addplot[color = black, line width = 0.25mm, mark = *, mark size = 1] coordinates {
(1, 1.5)(2, 1.3)
};
\addplot[color = black, line width = 0.25mm, mark = none, samples = 2, dashed] {1.4}; % Constant line
\legend{Plot1,}
\end{axis}
\begin{axis}[
ylabel={Percentage (\%)},
axis y line*=right,
ylabel near ticks,
ylabel style={rotate=-180},
hide x axis,
width=7cm,
height=6cm,
legend style={font=\footnotesize}
]
\addplot[color = black, mark = *, mark size = 1] coordinates {
(1, 0.5)(2, 0.6)
};
\addplot[color = black, line width = 0.25mm, mark = none, samples = 2, dashed] {0.53}; % Constant line
\legend{Plot2,}
\end{axis}
\end{tikzpicture}}
\caption{Performance}
\label{Plot:}
\end{subfigure}
\begin{subfigure}{0.49\textwidth}
\hfill%
\fbox{\begin{tikzpicture}
\begin{axis}[
title={},
xlabel={Epochs},
ylabel={Rewards},
ylabel near ticks,
legend pos=south east,
ymajorgrids=true,
grid style=densely dotted,
width=7cm,
height=6cm,
legend cell align={left},
legend style={font=\footnotesize}
]
\addplot[color = black, line width = 0.25mm, mark = *, mark size = 1] coordinates {
(1, 1.5)(2, 1.3)
};
\addplot[color = black, line width = 0.25mm, mark = none, samples = 2, dashed] {1.4}; % Constant line
\legend{Plot1,}
\end{axis}
\end{tikzpicture}}%
\caption{Action distribution}
\label{Plot:}
\end{subfigure}
\caption{Results}
\label{Plot:}
\end{figure}
\end{document}
I used this table to draw the plot using matplotlib.
Use two \begin{axis} ... \end{axis} environments, one for the left and the other for the right. You can find the relevant part axis y line in the code below.
To prevent the bars from being on top of each other, bar shift is used (and set to the half of the bar width so that the bars are glued together).
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{width=10cm,height=8cm,compat=1.16}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
ybar,
symbolic x coords={A,B,C,D},
bar width=0.6cm, bar shift=-0.3cm,
xtick=data,
axis y line*=left,
ylabel=axis1,
xlabel=name,
]
\addplot[draw=red,fill=red] coordinates {
(A,16) (B,18) (C,3) (D,10)
};
\end{axis}
\begin{axis}[
ybar,
symbolic x coords={A,B,C,D},
bar width=0.6cm, bar shift=0.3cm,
xtick=data,
axis y line*=right,
ylabel=axis2
]
\addplot[draw=blue,fill=blue] coordinates {
(A, 299239.74) (B, 292816.67) (C, 72799.22) (D, 116248.54)
};
\end{axis}
\end{tikzpicture}
\end{document}
I created following LaTeX/TikZ script to draw a figure:
\documentclass[tikz,border=2mm]{standalone}
\usetikzlibrary{arrows, chains}
\usetikzlibrary{positioning,shapes.multipart}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\node[draw, fill=yellow!96!black, rectangle,
align=center, inner sep=3ex, font=\sffamily, label=below: Label1] (Box1) {
\begin{tikzpicture}
\node[draw, shape=rectangle split, rectangle split parts=2,
inner sep=1ex, rounded corners=0pt,
fill=white, font=\vphantom{Q}\sffamily] (Innerbox) {One \nodepart{two} Two};
\end{tikzpicture}};
\node[draw, inner sep=1ex, right=of Box1, label=below: Label2] (Box2) {
\begin{tikzpicture}
\end{tikzpicture}
{\begin{tikzpicture}
\node[draw, fill=yellow!96!black, rectangle,
align=center, inner sep=3ex, font=\sffamily, label=below: Label3] (Box3) {Four};
\end{tikzpicture}}};
\draw (Box1) -- (Box2) -- (Box3);
\draw[dashed] (Innerbox.one east) -- (Box2);
\draw[dashed] (Innerbox.two east) -- (Box2);
\end{tikzpicture}
\end{document}
I want to solve following problems:
How can the boxes be aligned equal, so than the label below is always on the same level?
How can box "Four" be added (not within, but as a box like Box1) to the right of Box2, ideally with a dashed line from Box2 to Box3?
Desired structure:
[Box1] -- [Box2] -- [Box3]
My elementary approach to this picture:
\documentclass[tikz,border=2mm]{standalone}
\begin{document}
\begin{tikzpicture}
% left box
\filldraw [fill=yellow, draw=black, ultra thick] (0,0) rectangle (8,-10);
\filldraw [fill=white, draw=black, ultra thick] (2,-2) rectangle (6,-5);
\filldraw [fill=white, draw=black, ultra thick] (2,-5) rectangle (6,-8);
\node at (4,-3.5) [font=\sffamily] {\Huge One};
\node at (4,-6.5) [font=\sffamily] {\Huge Two};
% right box
\filldraw [fill=white, draw=black, ultra thick] (12,0) rectangle (20,-10);
\filldraw [fill=yellow, draw=black, ultra thick] (13,-1) rectangle (19,-6);
\node at (16,-3.5) [font=\sffamily] {\Huge Four};
% labels
\node at (4,-11) {\Huge 1};
\node at (16,-11) {\Huge 2};
\node at (16,-7) {\Huge 3};
% lines
\draw [ultra thick] (8,-5) -- (12,-5);
\draw [loosely dashed, ultra thick] (6,-3.5) -- (12,-4);
\draw [loosely dashed, ultra thick] (6,-6.5) -- (12,-6);
\end{tikzpicture}
\end{document}
And its output:
Here you can play with coordinates to align boxes as you like.
This tries to answer to part 1 of your question while part 2 of it is not well clear to me. Anyway if you like this code, you can develop it and edit box Four just by using \filldraw, \draw and \node as above.
I am trying to display a sphere in PGF/TikZ to illustrate the idea of great circles.
The code for my current result is:
\begin{tikzpicture}
\tikzfading[name=fade right,
left color=transparent!20,
right color=transparent!90]
\tikzfading[name=fade out,
inner color=transparent!100,
outer color=transparent!10]
\tikzfading[name=fade right gc,
left color=transparent!0,
right color=transparent!70]
\draw [<->, dashed] (0,-5) -- (0,5); % y-axis
\draw [->, dashed] (0, 0) -- (20:5); % x-axis
\draw [->, dashed] (0, 0) -- (200:5); % x-axis
\draw [->, dashed] (0, 0) -- (340:5); % z-axis
\draw [->, dashed] (0, 0) -- (160:5); % z-axis
\fill [color=cyan, opacity=0.15, path fading=fade out] (0,0) circle (4cm); % bounding circle
\fill [color=cyan, opacity=0.25, path fading=fade right, fading angle=90] (0,0) ellipse (4cm and 1cm); % x-y-axis area
% great circle 1
\draw [rotate=-40, color=red, path fading=fade right gc, fading angle=40] (0,0) ellipse (4cm and 1cm);
% great circle 2
\draw[rotate=5, color=red, path fading=fade right gc, fading angle=5] (0,0) ellipse (1.5cm and 4cm);
\end{tikzpicture}
How do I
find the two points of intersection of the two red ellipses (commented as great circle 1 and 2),
find the point of intersection of a line (originating at the center (0,0)) with a ellipse, and
place a little circle or rectangle there?
Placing a little circle or rectangle there is not an issue.
Thank you very much!
Check out section 4.1.4. of the TikZ and PGF manual, titled "The Intersection of the Circles." You need to use the intersections library, which allows you to use the name intersections key, as in \path [name intersections={of=path 1 and path 2}] ;. To use this, you'll need to use the name path key, as in \draw [name path = y axis, <->, dashed] (0,-5) -- (0,5) ; % y-axis. Accessing the intersections seems to vary between versions; my local copy of the manual has different instructions from the one I linked you to. However, at least on my version, you then access the intersections with (intersection-1), (intersection-2), etc. To get circles at each intersection in your example, then, I would change your code to look like the following:
\begin{tikzpicture}
\tikzfading[ name = fade right
, left color = transparent!20
, right color = transparent!90 ]
\tikzfading[name = fade out
, inner color = transparent!100
, outer color = transparent!10 ]
\tikzfading[name = fade right gc
, left color = transparent!0
, right color = transparent!70]
\draw [name path = y axis, <->, dashed] (0,-5) -- (0,5) ; % y-axis
\draw [name path = x- axis, ->, dashed] (0, 0) -- (20:5) ; % x-axis
\draw [name path = x+ axis, ->, dashed] (0, 0) -- (200:5) ; % x-axis
\draw [name path = z+ axis, ->, dashed] (0, 0) -- (340:5) ; % z-axis
\draw [name path = z- axis, ->, dashed] (0, 0) -- (160:5) ; % z-axis
% bounding circle
\fill [color=cyan, opacity=0.15, path fading=fade out]
(0,0) circle (4cm) ;
% x-y-axis area
\fill [color=cyan, opacity=0.25, path fading=fade right, fading angle=90]
(0,0) ellipse (4cm and 1cm);
% great circle 1
\draw [ name path = great circle 1
, rotate = -40
, color = red
, path fading = fade right gc
, fading angle = 40]
(0,0) ellipse (4cm and 1cm);
% great circle 2
\draw [ name path = great circle 2
, rotate = 5
, color = red
, path fading = fade right gc
, fading angle = 5]
(0,0) ellipse (1.5cm and 4cm);
% Intersections
\path [name intersections={of=great circle 1 and great circle 2}] ;
\foreach \i in {1,...,4}
\fill [color=red] (intersection-\i) circle (2pt) ;
\path [name intersections={of=y axis and great circle 1}] ;
\fill (intersection-1) circle (2pt) ;
\fill (intersection-2) circle (2pt) ;
\path [name intersections={of=y axis and great circle 2}] ;
\fill (intersection-1) circle (2pt) ;
\fill (intersection-2) circle (2pt) ;
\foreach \a in {x,z} {
\foreach \ss in {+,-} {
\def\s.{\ss} % Otherwise the space in `\a\s axis` would get gobbled.
\path [name intersections={of=\a\s. axis and great circle 1}] ;
\fill (intersection-1) circle (2pt) ;
\path [name intersections={of=\a\s. axis and great circle 2}] ;
\fill (intersection-1) circle (2pt) ;
}
}
\end{tikzpicture}
Other than the reformatting (to avoid the horizontal scroll bar), all I have changed of your existing code is to add the name path key to your axes and great circles. I then added the intersections code, which should be relatively self-explanatory. Remember to \usetikzlibrary{intersections} first, and everything should work.