Wrong macro expansion in pgfplots foreach and pgfplotsinvokeforeach - foreach

What I am trying to do is to place a node on a path drawn with \addplot inside the body of \pgfplotsinvokeforeach, at a different pos and label at each iteration. However, the macros for the position and label only expand with their value at last iteration.
This is similar to what happens when one users addlegendentry instead of addlegendentryexpanded. If I use \expandafter then I get nonsense numbers.
Here is my minimal example:
\documentclass{standalone}
\usepackage{tikz,pgfplots,pgfplotstable}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{tikzpicture}
\pgfplotstableread{
t 1.0 2.0 3.0
1 2 2 2
2 3 4 6
3 4 6 9
4 5 8 12
5 6 10 15
}{\loadedtable}
\begin{axis}[legend style={at={(-0.1, 1)}, anchor=north east},]
\pgfplotstablegetcolsof{\loadedtable}
\pgfmathsetmacro{\N}{int(\pgfplotsretval -1)}
\pgfplotsinvokeforeach{1,2,...,\N}{
\pgfmathsetmacro{\Dist}{#1/\N}
\pgfplotstablegetcolumnnamebyindex{#1}\of{\loadedtable}\to\Slope
\addplot+[] table[x=t, y index=#1]{\loadedtable}%
node[sloped, above,pos=\Dist]%
{\pgfmathprintnumber{\Slope}};%
\addlegendentryexpanded{%
Slope = \pgfmathprintnumber{\Slope}
and Dist = \pgfmathprintnumber{\Dist}}
}
\end{axis}
\end{tikzpicture}
\end{document}

Related

paired duos data with exclosure cages

( I'm French sorry if English bad)
I need help on how treat my data. Tell me if its not the good place to ask that
For 12 weeks I have followed grass height for 4 grassland (ABCD). With 1 measurement per week per grassland.
In each grassland, I have placed an exclosure cage so animals cannot eat grass.
for each grassland :
A : 9 exlcosure cages
B : 6 exlcosure cages
C : 6 exlcosure cages
D : 8 exlcosure cages
measurements were done like this:
Once a Week
5 measurements per exclosure (each corner and middle) AND 5 measurements 10 meter in west (each corner and middle of an imaginary square)
SO each exclosore is paired with an imaginary corner where grass can be eaten.
so in total for exemple on grassland A :
65 mesurement on exclosure AND 65 on correspondant imaginary square
for 12 weeks
Here is the stat question: does the grass in exclosure is higher than in the imaginary square? ( I want to see if red deer uses my grassland, then determine which one are the best nor with places are most used in the grassland)
thanks
tell me if I need to do something to be more precise

gnuplot plot xy cspline with data points in order

Here is a minimum example:
set xrange [31:42]
set yrange [3.5:6.5]
set nokey
plot "-" using 2:3 smooth cspline
2015 34 4
2016 41 5
2017 40 6
2018 32 6
The result looks nice but ignores the time series:
minimal example using splot instead of plot:
set view map
splot "-" using 2:3:1 with line
2015 34 4
2016 41 5
2017 40 6
2018 32 6
The result is correct but does not look nice:
How can I smooth this as in the first example?
My solution: Make gnuplot output a complex graph without this troublesome non-monotonic curve to a LaTeX2e picture, draw this curve separately using the LaTeX2e TikZ package, and edit the picture to include the curve in the correct position and scale.
\addplot[smooth] coordinates {
(34,4)
(41,5)
(40,6)
(32,6)
}

How to perform "complex" calculations in LaTeX/TikZ

I expect this question has already been answered a thousand times, but I just cannot find a solution to my issue =(
I want to calculate some values in LaTeX (TikZ), some of which are lengths (e.g. 10 pt), some are not. As long as calculations are of very simple forms like a*b+c everything is fine, but if I need brackets like (a+b)*(c+d) LaTeX complains. Furthermore, if I have nested definitions, these are not solved as expected. Example:
\def\varA{1+2}
\def\varB{10}
% I want to calculate (1+2)*10 or 10*(1+2), respectively.
\def\varC{\varA*\varB} % evaluates to 21
\def\varD{\varB*\varA} % evaluates to 12
So basically my question is: What is the correct (or recommended) way to do calculations in LaTeX?
As a more realistic example, here is something I actually want to do and just can't:
% total height of my TikZ image
\def\myheight{20ex}
% five nodes shall be drawn as a stack
\def\numnodes{5}
% but there shall be some space at the top (like a 6th node)
\def\heightpernodeA{\myheight / (\numnodes + 1)} % fails whenever I want to use it
% workaround?
\def\numnodesplusone{\numnodes + 1}
\def\heightpernodeB{\myheight / \numnodesplusone} % fails for the reason explained above
Unfortunately I can not redefine \numnodes to be 6 as I use the variable for various calculations.
best regards
You can use \pgfmathsetmacro for more complex calculation. You'll need to remove the unit in myheight though:
% total height of my TikZ image
\def\myheight{20}
% five nodes shall be drawn as a stack
\def\numnodes{5}
% but there shall be some space at the top (like a 6th node)
\pgfmathsetmacro\heightpernodeA{\myheight / (\numnodes + 1)}
You can add the unit back when you use it: \draw (0,0) -- ({\heightpernodeA ex},{1});

Delphi POS printing receipt text alignment [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
How can I print to POS printer if the output format should be like this?
paper size 3 inches
line 1 = ITEM DESCRIPTION
line 2 = QTY UNIT x UNIT PRICE_ _ _ _ _ _ _ TOTAL PRICE
Total PRICE is right align
sample format
BOND PAPER
1 REAM x 100.00 --------------- 100.00
BOND PAPER 2
2 REAM X 100.00 --------------- 200.00
BOND PAPER 3
1 REAM X 1,354.00 ----------- 1,354.00
POS printers typically use fixed width fonts, so right aligning the value of TotalPrice is simply a matter of calculating the amount of Padding to insert into the line after the ItemDescription.
In your example, you are using a 38 character line, so if the length of ItemDescription is 15 characters long, and the length of the TotalPrice is 6 characters long, then Padding needs to be 38 - (ItemDescription + TotalPrice) = 38 - (15 + 6) = 17 characters long. But since you seem to add a space immediately after ItemDescription and before TotalPrice your Padding needs to subtract these 2 additional characters... so, in that case Padding needs to be 15 characters long.
Applying this to your last line:
Length(ItemDescription) = 17
Length(TotalPrice) = 8
Padding = 38 - (17 + 8 + 2) = 11
So the final line that you will send to your fixed width font POS will be:
PrintLine = Concat(ItemDescription,' ',StringOfChar('-',Padding),' ', TotalPrice)
This should always right align TotalPrice for the given fixed width character paper size (change the 38 to whatever the number of characters your POS printer is rated at), and all long as the total length of ItemDescription, TotalPrice and your single character spaces does not exceed the total character width of the printer (you should probably check this before calculating Padding).

iOS CNN Convolution Edgemode

So I've been experimenting with CNNs on iOS using the new iOS 10 APIs, and I'm not sure why I'm getting the following results.
So I initialize a plain MPSCNNConvolution class with a weight array of 1.0 and a bias array of 0.0, and kernel width and height of 3. For testing I'm using only a single feature channel. I'm setting the MPSImageEdgeMode to
convolution.edgeMode = .clamp
which, according to the iOS Docs should do the following
Out-of-bound pixels are clamped to the nearest edge pixel.
However, forwarding a texture filled with 1.0s, I get the following result:
4 6 4
6 9 6
4 6 4
which is exactly the same as leaving the edgeMode parameter to its default value .zero - so apparently for the top-left corner (0/0), only the values (0/0), (1/0), (1/1) and (0/1) are considered, and the remaining 5 out-of-bounds values are zero rather then the clamped 1 I expected.
Shouldn't the .clamp parameter result in the following?
9 9 9
9 9 9
9 9 9
Is the expected behaviour, or is there something I'm not considering here?
Thanks!

Resources