0

It is easy to do with \addplot3 but I want a 2d plot.

I want to plot a scatter plot: g(x,y) value on vertical axis and f(x,y) on horizontal axis. AFAIK, The parametric plot syntax allows only one axis value as its argument e.g. How to plot functions like ‎‎‎‎‎x=f(y)‎‎ using TikZ?

Any solution which uses tikz-datavisualization, pgfplot or gnuplot is fine.

  • Did you try \addplot with keys x expr, y expr ? – percusse Sep 22 '16 at 6:02
  • @percusse Thanks. I was bit successful with datavisualization library using func x and func y. I'll try now. – Dilawar Sep 22 '16 at 6:05
3

I managed to do it using both pgfplot and tikz-datavisualization. Though pgfplot solution is better.

Pgfplot solution

% create a new table with 10 rows and columns 'x' and 'y':
\pgfplotstablenew
[
    % define how the 'new' column shall be filled:
    create on use/x/.style ={ create col/expr ={100*rand}},
    create on use/y/.style ={ create col/expr ={100*rand}},
    columns={x,y}
] {1000} \mydata
% show it:
%\pgfplotstabletypeset\mydata

\begin{tikzpicture}[scale=1
    , every node/.style={}
    ]
    \begin{axis}[
            xlabel=$||x|-|y||$,ylabel=$|x+y|$
    ]
        \addplot[ only marks, color = blue ] table [
            , x expr=abs(abs(\thisrowno{0}) - abs(\thisrowno{1}))
            , y expr=abs(\thisrowno{0}+\thisrowno{1})
        ] {\mydata};
    \end{axis}

\end{tikzpicture}   

pgfplot solution. I could get random sampling easily using <code>pgfplotstables</code>

tikz-datavisualization solution

Almost same but could not get random sampling of interval.

\begin{tikzpicture}[scale=1 , every node/.style={} ]
    \datavisualization[
       scientific axes=clean, visualize as scatter
       , scatter={
           style={mark=*
               , mark options={color=blue,mark size=2pt} } 
           }
    ]
    data[ format=function ] {
        var i : interval [-100:100];
        var j : interval [-100:100];
        func y = abs(\value i + \value j) ;
        func x = abs( abs(\value i) - abs(\value j) );
    };

\end{tikzpicture}   

<code>tikz-datavisualization</code> solution. I could not get random sampling between interval.

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.