swiftplot
swiftplot copied to clipboard
Implement new chart type - Polar Plot
The current LineChart implementation uses rectangular coordinates. It would be good to have a plot type that helps us plot data using polar coordinates. Details about what a polar plot is can be found here. A simple example of a polar plot can be found here.
This task will require you to implement the following:
- A new plot type (PolarPlot) similar to LineChart, BarChart implemented currently. (Very basic implementation. You need not implement support for multiple series, although that would be a great addition.)
- Add functions to atleast two from the three renderers (AGG/SVG/CoreGraphics) to draw an empty circle.
The input type can be Pair<FloatConvertible , FloatConvertible>. The end user should be able to create plots using an array of (r,θ) values or a function that returns r at a specific θ [ r = f(θ) ].
Hi! I'm not sure whether I'll take this task or not, but is it okay if I look at it in the meantime?
Thanks!
Sure @Qwerty71 ! Let me know if you need any help getting started.
Hey! I was wondering how to resize a plot so that it's in a 1:1 ratio (for example, ax.set_aspect() in matplotlib in python). I've got the polar coordinates working, I just need to get it into an organized package file.
In addition, am I allowed to use LineChart within my implementation? Or would you like me to create it from scratch?
At the moment there's no way to set the aspect ratio. But while creating the plot the end user may set the width and height of the plot in the initializer.
I'd be interested to see how you've used LineChart to get polar plots working. Also, could you share preliminary plots that you have been able to make?
Sure! Should I add the notebook to /Notebook or just link it here? It goes through all the procedures and how they should be implemented.
On Sat, Jan 18, 2020, 2:08 AM Karthik Ramesh Iyer [email protected] wrote:
At the moment there's no way to set the aspect ratio. But while creating the plot the end user may set the width and height of the plot in the initializer.
I'd be interested to see how you've used LineChart to get polar plots working. Also, could you share preliminary plots that you have been able to make?
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/KarthikRIyer/swiftplot/issues/39?email_source=notifications&email_token=AH4TA2DJ3XA7MQW5WJ5FJPLQ6KTHFA5CNFSM4JRNP5XKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEJJSF2Q#issuecomment-575873770, or unsubscribe https://github.com/notifications/unsubscribe-auth/AH4TA2E2YAPLZD6W42VAO6TQ6KTHFANCNFSM4JRNP5XA .

Here's a basic polar plot that I made. I had to hard-code the circles, but when I implement them, I'll automate them to behave such as grid lines. Inside, there is a limacon with 4 "petals," and a spiral.
As you can see, the image appears to be stretched - yes, those should be circles, not ovals - so that's why I was asking about the aspect ratio.
If you look at the legend, you'll see that it contains a graph for how addFunction
would work (e.g. r = 2costheta) and addSeries
(hardcoded values for r and theta).
I've selected this task on the GCI homepage - I linked to my notebook there.
There's no way to set the aspect ratio explicitly. You'll have to set the width and height. Also I'd prefer if you didn't reuse LineChart to implement polar plots because in a polar plot we don't want the coordinates to be (x,y), but (r,θ) just like in matplotlib. We want results as close as possible to matplotlib so that people can transition from matplotlib to swiftplot easily.
Alright. In this version, the user does still enter in r and theta, the Cartesian conversion is done behind the scenes.
On Sun, Jan 19, 2020, 3:55 AM Karthik Ramesh Iyer [email protected] wrote:
There's no way to set the aspect ratio explicitly. You'll have to set the width and height. Also I'd prefer if you didn't reuse LineChart to implement polar plots because in a polar plot we don't want the coordinates to be (x,y), but (r,θ) just like in matplotlib. We want results as close as possible to matplotlib so that people can transition from matplotlib to swiftplot easily.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/KarthikRIyer/swiftplot/issues/39?email_source=notifications&email_token=AH4TA2ETOVUOSBLG5S7VU7LQ6QIQZA5CNFSM4JRNP5XKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEJKMQ4A#issuecomment-575981680, or unsubscribe https://github.com/notifications/unsubscribe-auth/AH4TA2DCBDZ622PRC3Z5GKDQ6QIQZANCNFSM4JRNP5XA .
Just an update - I've solved my previous problem (converting Float to FloatConvertible), and I've got the code working (I just modified the code for LineChart.swift, I will mention that on the top of the code). All I need to do now is add the circle "gridlines," and I'll also see if I can fix the aspect ratio as well.
The notebook demonstrating how it works (now updating, actually getting code from my forked repo) is on the GCI comments.
Would you like me to provide compatibility with all of the addSeries
functions (you can either input a list of Point
s, x
and y
, or just y
)?
Input can be an array of (r,theta) or single r,theta pairs.
Instead of trying to fix the aspect ratio, just use one parameter like imageSize, which will be both the width and height of the image.
Hey, I'm getting this error after trying to install SwiftPlot after making my changes:
undefined symbol: _ZN14CPPAGGRenderer17draw_empty_circleEfffPKv
I created a new function, draw_empty_circle as per the task request. I checked in all the .cpp and .h files for AGGRenderer, CAGGRenderer, and CPPAGGRenderer, and it's defined in all of those.
The inputs of (r, theta) are working for both addSeries() and addFunction(). All I need is to implement this and I'll be set.
Could you open a PR with your updated code. I'll take a look.
With the current code (that produces the error)? Or everything without that portion?
The complete code with the error.
Ok.