I've tried this code.

import ggplotd.ggplotd;
import ggplotd.geom;
import ggplotd.aes;
import ggplotd.axes;
import std.math;

auto r(double theta)
{
        return 2 * sin(6*theta);
}

auto getX(double theta)
{
        return r(theta) * cos(theta);
}

auto getY(double theta)
{
        return r(theta) * sin(theta);
}

void main()
{
    import std.array : array;
    import std.algorithm : map;
    import std.range : iota;
        
    auto theta = iota(0, 2*PI, 0.1).array;
    auto xs = theta.map!((x) => getX(x)).array;
    auto ys = xs.map!((x) => getY(x)).array;

auto gg = GGPlotD().put( geomLine( Aes!(typeof(xs), "x", typeof(ys), "y")(xs, ys) ) );

    gg.put( xaxisRange(-5, 5) ).put( xaxisLabel( "x" ) );
    gg.put( yaxisRange(-5, 5) ).put( yaxisLabel( "y" ) );
    gg.put( xaxisOffset(0) ).put( yaxisOffset(0) );
    gg.save( "output.png", 500, 300 );
}

And I got the output: http://imgur.com/KwLYJpN

Expected:
https://www.wolframalpha.com/input/?i=polar+plot+2*sin(6*theta)

I need to somehow activate "polar" mode in ggplotd. Thanks.



Reply via email to