Thread overview | ||||||
---|---|---|---|---|---|---|
|
September 18, 2016 polar coordinates with ggplotd | ||||
---|---|---|---|---|
| ||||
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. |
September 18, 2016 Re: polar coordinates with ggplotd | ||||
---|---|---|---|---|
| ||||
Posted in reply to brocolis | On Sunday, 18 September 2016 at 22:07:31 UTC, brocolis wrote:
> 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.
Found an error in ys line. Thanks.
|
September 19, 2016 Re: polar coordinates with ggplotd | ||||
---|---|---|---|---|
| ||||
Posted in reply to brocolis | On Sunday, 18 September 2016 at 22:13:35 UTC, brocolis wrote:
> Found an error in ys line. Thanks.
Does that mean you solved it?
Currently there is no special support for other coordinate systems, but I recently added Guides for x/y coordinates which should make this relatively straightforward to implement and is next on the list. Not sure when I'll get a chunk of time to implement it though.
For now you will have to convert the coordinates yourself, before plotting them.
|
September 20, 2016 Re: polar coordinates with ggplotd | ||||
---|---|---|---|---|
| ||||
Posted in reply to Edwin van Leeuwen | On Monday, 19 September 2016 at 12:34:56 UTC, Edwin van Leeuwen wrote:
> On Sunday, 18 September 2016 at 22:13:35 UTC, brocolis wrote:
>> Found an error in ys line. Thanks.
>
> Does that mean you solved it?
>
> Currently there is no special support for other coordinate systems, but I recently added Guides for x/y coordinates which should make this relatively straightforward to implement and is next on the list. Not sure when I'll get a chunk of time to implement it though.
>
> For now you will have to convert the coordinates yourself, before plotting them.
Yeah, problem solved. Thanks.
|
Copyright © 1999-2021 by the D Language Foundation