Creating a diagram with quantity of values - latex

I'm trying to create a Diagram with following specification:
x-Axis: Values from file.
y-Axis: Quantity of the values
Here is an image to describe, what I need.
The order of the values is random.
I hope, anybody can help me with this problem.
Here is an example.
\documentclass[paper=a4,12pt,version=last]{scrartcl}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[ymin=0,
x tick label style={/pgf/number format/1000 sep=},
xlabel={values},
y tick label style={/pgf/number format/1000 sep=},
ylabel={amount of values}]
\addplot table [ ... ,col sep=semicolon] {data.csv};
\end{axis}
\end{tikzpicture}
\end{document}
Instead of the three points shall be a command to calculate the y-values.
In the data-file are the values in one clolumn.

Related

circuitikz - move current labels closer to current arrow

how can I move the current label closer to the current arrow. I.e. I want to move the i_1 closer to the arrow.
MWE:
\documentclass{standalone}
\usepackage[european,cuteinductors,fetbodydiode,straightvoltages]{circuitikz}
\begin{document}
\begin{figure}[htb]
\centering
\begin{tikzpicture}[scale=0.65, arrowmos]
\coordinate (zero) at (0,0);
\draw (zero) to[R,-*,R=$R_1$,i>_=$i_1$] ++(2.75,2);
\end{tikzpicture}
\end{figure}
\end{document}
I tried to put a \vspace in front of the label but it didn't work.
I propose two solutions here: the first one is using a fake label and then setting the label manually (with a lot of flexibility), or using the provided styling for labels. Details in comments; you need a quite recent circuitikz for using this solution (>=1.4.2).
\documentclass{standalone}
\usepackage[european,cuteinductors,fetbodydiode,straightvoltages]{circuitikz}
\begin{document}
\centering
\begin{tikzpicture}[scale=0.65, arrowmos]
\coordinate (zero) at (0,0);
% First option
% use a blank label for the current, and name the component
\draw (zero) to[R,-*,R=$R_1$,i>_=~,name=myI] ++(2.75,2);
% manually place the label where you like
% myIcurrent is the normal position where the blank label is set
\node[below=1mm, anchor=center, red] at (myIcurrent) {$i_1$};
% you can also use bipole current style to change inner sep;
\draw (2,0) to[bipole current style={inner sep=0pt}, R,-*,R=$R_1$,i>_=$i_1$] ++(2.75,2);
\end{tikzpicture}
\end{document}
See circuitikz manual, https://texdoc.org/serve/circuitikz/0#subsection.5.6 .

IguanaTex and TikZ

I'm experimenting with importing some tikzpicture into a PowerPoint using IguanaTeX.
This is the code I am experimenting with:
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.7}
\begin{document}
\begin{tikzpicture}[scale=0.50,local bounding box=picture, baseline=(picture.south),
declare function={binom(\k,\n,\p)=\n!/(\k!*(\n-\k)!)*\p^\k*(1-\p)^(\n-\k);}
]
\begin{axis}[
samples at={0,...,40},
yticklabel style={
/pgf/number format/fixed,
/pgf/number format/fixed zerofill,
/pgf/number format/precision=1
},
ybar=0pt, bar width=1
]
\addplot [fill=cyan, fill opacity=0.5] {binom(x,40,0.2)}; \addlegendentry{$p=0.2$}
\addplot [fill=orange, fill opacity=0.5] {binom(x,40,0.5)}; \addlegendentry{$p=0.5$}
\end{axis}
\end{tikzpicture}
\end{document}
Note to get it to appear correctly, you need to change from the default DVI to pdflatex in IguanaTeX.
Firstly, the graph appears BUT there is some unnecessary whitespace that occurs at the bottom. As such, the resulting graphic is too large for the slide. How can I remove this?
Secondly, how can I change the axes etc. to be displayed in white, instead of the default black, so I can see the graph on a PowerPoint slide with a black background?
you can avoid the space between your graph and the axis by setting ymin=0
to change axis, labels, legend etc. to white, you can make the following adjustments:
\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.7}
\pgfplotsset{
axis line style={white},
every axis label/.append style ={white},
every tick label/.append style={white},
every axis legend/.append style={white,fill=black},
every axis/.append style={tick style={white}}
}
\pagecolor{black}
\begin{document}
\begin{tikzpicture}[scale=0.50,local bounding box=picture, baseline=(picture.south),
declare function={binom(\k,\n,\p)=\n!/(\k!*(\n-\k)!)*\p^\k*(1-\p)^(\n-\k);}
]
\begin{axis}[
samples at={0,...,40},
yticklabel style={
/pgf/number format/fixed,
/pgf/number format/fixed zerofill,
/pgf/number format/precision=1
},
ybar=0pt, bar width=1,
ymin=0,
]
\addplot [fill=cyan, fill opacity=0.5,draw=white] {binom(x,40,0.2)}; \addlegendentry{$p=0.2$}
\addplot [fill=orange, fill opacity=0.5,draw=white] {binom(x,40,0.5)}; \addlegendentry{$p=0.5$}
\end{axis}
\end{tikzpicture}
\end{document}

how to align two tikzpicture plots in latex

I am trying to use the subfigure method shown at https://www.latex-tutorial.com/tutorials/figures/ to make side by side plots but I can't seem to adjust the size and get them to go side by side...what am i doing wrong?
Below is code I am using
\begin{figure}
\centering
\begin{subfigure}[b!]{0.3\textwidth}
\begin{tikzpicture}
\begin{axis}[
axis y line = middle,
axis x line = middle,
xlabel = $x$,
ylabel = {$f(x) = x^3$},
grid=major,
]
\addplot [
domain=-3:3,
samples=100,
color=red,
]
{x^3};
\addlegendentry{$x^3$}
%
\addplot [
domain=-3:3,
samples=100,
color=blue,
]
{x^3 + 3};
\addlegendentry{$x^3 + 3$}
%
\addplot [
domain=-3:3,
samples=100,
color=green,
]
{x^3 - 3};
\addlegendentry{$x^3 - 3$}
\end{axis}
\end{tikzpicture}
\end{subfigure}
%\hfill
\begin{subfigure}[b]{0.3\textwidth}
\begin{tikzpicture}
\begin{axis}[
axis y line = middle,
axis x line = middle,
xlabel = $x$,
ylabel = {$f(x) = x^3$},
grid=major,
]
\addplot [
domain=-3:3,
samples=100,
color=red,
]
{x^3};
\addlegendentry{$x^3$}
\end{axis}
\end{tikzpicture}
\end{subfigure}
\caption{lajsdfls}
\end{figure}
There are two problems with your code.
First horizontal alignment of the figures was incorrect, but this can easily be fixed by using
\begin{subfigure}[b]{0.3\textwidth}
instead of
\begin{subfigure}[b!]{0.3\textwidth}
concerning the width, what is done when you create a subfigure environment is that a minipage of the indicated width is created. But is is up to you to respect this width with your content, no rescaling is done.
For instance, if, in a subfigure, you include an image and give it a width of \linewidth, the width will be respected. But if you give this image a 15cm width, probably it will be larger than you minipage. But LaTeX will respect your directives (and indicate an overfull hbox).
This is the problem that you have. Your plots are too large and overlap.
There are two ways to fix that.
You can give a width=\linewidth parameter to the axis environment, but it generally requires a redesign of your plot
you can rescale the box created by tikz. The most flexible way to do that is with adjustbox package
\documentclass{article}
\usepackage{subcaption}
\usepackage{tikz}
\usepackage{pgfplots}
\usepackage{adjustbox}
\begin{document}
\begin{figure}
\centering
\begin{subfigure}[b]{0.45\textwidth}
%%% \begin{adjustbox}{width=\linewidth} % rescale box
\begin{tikzpicture}
\begin{axis}[
%%% width=\linewidth, % or modify the plot width
axis y line = middle,
...
...
\end{axis}
\end{tikzpicture}
%%% \end{adjustbox} %
\end{subfigure}%
\hfill
\begin{subfigure}[b]{0.45\textwidth}
etc.
Adding a width parameter to the axis environment
Rescaling with adjustbox
BTW, if you do not intend to add subcaptions to your plots, the subfigure environment is useless, and you can just put your (properly scaled) tikzpictures side by side separated by an \hfill.

How to fix overlap labels on y-axis - Latex

I create a simple diagram in Latex (tikzpicture) and some labels on the y-axis overlap as you can see in the picture
\begin{figure}[h!]
\centering
\begin{tikzpicture}
\begin{axis}[
title=\textbf{example},
ybar,
width=10cm, height=5cm, bar width=30pt,
enlargelimits=0.5,
symbolic x coords={2013,2014,2015,2016}, xtick={2013,2014,2015,2016},
ytick=data,
]
\addplot coordinates
{(2013,794) (2014,1208) (2015,1183) (2016,1259)};
\end{axis}
\end{tikzpicture}
\end{figure}
How can I fix this, I don't want to make the diagram much higher?
I suggest to trust pgfplots to create readable axis labels instead of manually interfering:
\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\begin{figure}[htbp]
\centering
\begin{tikzpicture}
\begin{axis}[
title=\textbf{example},
ybar,
width=10cm, height=5cm, bar width=30pt,
enlargelimits=0.5,
symbolic x coords={2013,2014,2015,2016}, xtick={2013,2014,2015,2016},
% ytick=data,
]
\addplot coordinates
{(2013,794) (2014,1208) (2015,1183) (2016,1259)};
\end{axis}
\end{tikzpicture}
\end{figure}
\end{document}
If you really need to show the exact numerical values, a plot might not be the suitable form of visualization and a table might be better suited.

LaTeX pgfplots use strings for barchart label from .csv

I'm trying to use data from a .csv file to create a barchart with labels that are non-numeric. I've looked through a few older examples, but they seem large and clunky. I'm hoping there's a better way. Here's what I have so far as a MWE:
\documentclass[11pt]{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.9}
\begin{document}
\begin{tikzpicture}
\begin{axis}[xlabel=x axis label,ylabel=y axis label]
\addplot [ybar] table [symbolic x coords=Month, y=Dozers, col sep=comma] {cnrldata.csv};
\end{axis}
\end{tikzpicture} \\
\end{document}
From this I of course get the error:
Package PGF Math Error: Could not parse input 'May 14' as a floating point number, sorry. The unreadable part was near 'May 14'.. ... y=Dozers, col sep=comma] {data.csv};
The data in the table looks like this:
Month, Dozers,
January, 0.85,
February, 0.7,
Your usage of symbolic x coords is wrong. Read the manual.
Tip: You are more likely to get such questions answered on TeX.SX.
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
xlabel={$x$ axis label},
ylabel={$y$ axis label},
symbolic x coords={January,February,March,April,May},
]
\addplot [ybar] table [x=Month, y=Dozers, col sep=comma] {
Month, Dozers
January, 0.85
February, 0.7
March, 0.6
April, 0.9
May, 0.4
};
\end{axis}
\end{tikzpicture}
\end{document}

Resources