2

Sorry for my incorrect english.

I have some data values. I choose an array as a data structure (it could be any another data structure). I wish to use those data values to calculate some other data values and then plot those (new data values). My idea was to use the data[format = function] syntax. But I couldn't achieve it and I was forced to calculate the new data values first, than store the (data value) in a file, then load the file to plot it. This is a lot of handwork. Is there a way to do this automatically with the data[format = function] syntax? Any other solution is welcome too.

Here is my code (sample file):

\documentclass{scrartcl}
\usepackage{tikz,siunitx}
\usetikzlibrary{datavisualization.formats.functions}
\begin{document}

  %data values:

  \def\RTable{{100,100.391,100.781,101.172,101.562,101.953,102.343,102.733,103.123,103.513,103.903,104.292,104.682,105.071,105.46,105.849,106.238,106.627,107.016,107.405,107.794,108.182,108.57,108.959,109.347,109.735,110.123,110.51,110.898,111.286,111.673,112.06,112.447,112.835,113.221,113.608,113.995,114.382,114.768,115.155,115.541,115.927,116.313,116.699,117.085,117.47,117.856,118.241,118.627,119.012,119.397,119.782,120.167,120.552,120.936,121.321,121.705,122.09,122.474,122.858,123.242,123.626,124.009,124.393,124.777,125.16,125.543,125.926,126.309,126.692,127.075,127.458,127.84,128.223,128.605,128.987,129.37,129.752,130.133,130.515,130.897}}

  %prints the result to the console:

  %\foreach \i in {0, ..., 80}
    %{
     %\pgfmathparse{abs(\RTable[\i] - 100 - 3.0897 / 8 * \i)}\i, \pgfmathresult\\
    %}

  %than stores the result in a file by hand

  \begin{tikzpicture}
    \datavisualization[
                       scientific axes = {clean, end labels},
                       x axis = {label = $\frac{\vartheta}{\si{\celsius}}$},
                       y axis = {label = $\frac{\Delta\vec R(\vartheta)}{\si{\ohm}}$},
                       visualize as line = x,
                      ]

    %loads the file and plots it:

    data[
         headline = {x, y},
         read from file = Delta_R_values.dat
        ];

    %this is what I wish to use:

    %data[format = function] {
                             %var x : interval [0 : 80];
                             %func y = abs(\RTable[\value x] - 100 - 3.0897 / 8 * \value x);
                            %};
  \end{tikzpicture}
\end{document}

Correct result:Correct result

However, if I use the commented code in the example above, I get this incorrect result instead:

incorrect result

Thank you for your help in advance!

  • Welcome! These are both fine questions, but please ask one question per question! I'd recommend editing this one to include one of them and asking a new question for the other one. This is more likely to get you helpful answers since, as it stands, I'd need to know how to answer both in order to answer your question. But, although I've used fpu, I have no clue about the first question at all. – cfr Jan 15 '17 at 0:00
  • 1
    Also, for the first question, at least, you need to provide a sample file. Nobody but you can compile your code as it stands. – cfr Jan 15 '17 at 0:03
  • The array syntax does not seem to be supported by the fpu parser. However, the data you've given in the example works without error for me with the regular parser. Is it your real data which gives the problem? – cfr Jan 15 '17 at 0:36
  • Hello @cfr! Thank you for a comment. I edited my question as you asked and created a new (one)[tex.stackexchange.com/questions/348799/…. – Su-47 Jan 15 '17 at 13:00
  • 1
    Hello @cfr! Thank you for a comment. You are right. It compiles, but the result on your picture is wrong (I got the same wrong result). I added a picture with the correct result to my question. – Su-47 Jan 15 '17 at 23:17
1

If you use visualize as scatter, it is a bit easier to guess what the problem is. Basically, if you don't tell TikZ how many samples to use, it guesses. Usually, this is reasonable, but in this case, I think, it means that the points used may not be in the array at all, because the chances that evenly spaced samples will hit integers is relatively low.

Specifying a suitable number of samples does the trick. That is,

\begin{filecontents}{\jobname.dat}
0, 0.0
1, 0.0048
2, 0.0086
3, 0.0134
4, 0.0172
5, 0.022
6, 0.0258
7, 0.0296
8, 0.0334
9, 0.0372
10, 0.041
11, 0.04381
12, 0.0476
13, 0.0504
14, 0.0532
15, 0.056
16, 0.0588
17, 0.0616
18, 0.0644
19, 0.0672
20, 0.07
21, 0.07181
22, 0.07361
23, 0.0764
24, 0.0782
25, 0.08
26, 0.0818
27, 0.0826
28, 0.0844
29, 0.0862
30, 0.087
31, 0.0878
32, 0.08861
33, 0.09041
34, 0.0902
35, 0.091
36, 0.0918
37, 0.0926
38, 0.0924
39, 0.0932
40, 0.093
41, 0.0928
42, 0.0926
43, 0.0924
44, 0.09221
45, 0.091
46, 0.0908
47, 0.0896
48, 0.0894
49, 0.0882
50, 0.087
51, 0.0858
52, 0.08461
53, 0.0834
54, 0.0812
55, 0.08
56, 0.0778
57, 0.0766
58, 0.0744
59, 0.0722
60, 0.07
61, 0.06781
62, 0.0646
63, 0.06241
64, 0.0602
65, 0.057
66, 0.0538
67, 0.0506
68, 0.04741
69, 0.0442
70, 0.041
71, 0.0378
72, 0.0336
73, 0.03041
74, 0.0262
75, 0.022
76, 0.0188
77, 0.0146
78, 0.0094
79, 0.0052
80, 0.001
\end{filecontents}
\documentclass[border=10pt,multi,tikz]{standalone}
\usepackage{siunitx}
\usetikzlibrary{datavisualization.formats.functions}
\begin{document}
\def\RTable{{100,100.391,100.781,101.172,101.562,101.953,102.343,102.733,103.123,103.513,103.903,104.292,104.682,105.071,105.46,105.849,106.238,106.627,107.016,107.405,107.794,108.182,108.57,108.959,109.347,109.735,110.123,110.51,110.898,111.286,111.673,112.06,112.447,112.835,113.221,113.608,113.995,114.382,114.768,115.155,115.541,115.927,116.313,116.699,117.085,117.47,117.856,118.241,118.627,119.012,119.397,119.782,120.167,120.552,120.936,121.321,121.705,122.09,122.474,122.858,123.242,123.626,124.009,124.393,124.777,125.16,125.543,125.926,126.309,126.692,127.075,127.458,127.84,128.223,128.605,128.987,129.37,129.752,130.133,130.515,130.897}}
\begin{tikzpicture}
  \datavisualization[
    scientific axes = {clean, end labels},
    x axis = {label = $\frac{\vartheta}{\si{\celsius}}$},
    y axis = {label = $\frac{\Delta\vec R(\vartheta)}{\si{\ohm}}$},
    visualize as line = x,
  ]
  data[
    headline = {x, y},
    read from file = \jobname.dat
  ];
\end{tikzpicture}
\begin{tikzpicture}
  \datavisualization[
    scientific axes = {clean, end labels},
    x axis = {label = $\frac{\vartheta}{\si{\celsius}}$},
    y axis = {label = $\frac{\Delta\vec R(\vartheta)}{\si{\ohm}}$},
    visualize as line,
  ]
  data [format=function] {
    var x : interval [0:80] samples 81;
    func y = {abs(\RTable[\value x]-100-3.0897*\value x/8)};
  };
\end{tikzpicture}
\end{document}

produces 2 similar graphs.

2 twin peas in a pod?

|improve this answer|||||
  • Hello @cfr! Sorry for a the long absence. Thank you for the answer. By the way: In the line func y = {abs(\RTable[\value x]-100-3.0897*\value x/8}; is missed the closing ). But it still works. I wonder why? – Su-47 Jan 20 '17 at 20:24
  • @Su-47 That is strange. It must somehow take the } to imply )}, do you think? – cfr Jan 20 '17 at 23:52
  • Hello @cfr! Thank you for a comment! You are right it must somehow take the closing }. But I don't know what is going on there. Finally I'm a TikZ & PGF beginner. Maybe someone have an answer for it? – Su-47 Jan 21 '17 at 15:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.