swiftplot icon indicating copy to clipboard operation
swiftplot copied to clipboard

Implement new chart type - Polar Plot

Open KarthikRIyer opened this issue 4 years ago • 19 comments

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(θ) ].

KarthikRIyer avatar Nov 25 '19 19:11 KarthikRIyer

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!

areebg9 avatar Jan 13 '20 17:01 areebg9

Sure @Qwerty71 ! Let me know if you need any help getting started.

KarthikRIyer avatar Jan 13 '20 17:01 KarthikRIyer

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?

areebg9 avatar Jan 17 '20 23:01 areebg9

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?

KarthikRIyer avatar Jan 18 '20 07:01 KarthikRIyer

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 .

areebg9 avatar Jan 18 '20 13:01 areebg9

Screen Shot 2020-01-18 at 9 40 56 AM

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.

areebg9 avatar Jan 18 '20 14:01 areebg9

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).

areebg9 avatar Jan 18 '20 14:01 areebg9

I've selected this task on the GCI homepage - I linked to my notebook there.

areebg9 avatar Jan 18 '20 15:01 areebg9

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.

KarthikRIyer avatar Jan 19 '20 08:01 KarthikRIyer

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 .

areebg9 avatar Jan 19 '20 14:01 areebg9

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.

areebg9 avatar Jan 19 '20 22:01 areebg9

Would you like me to provide compatibility with all of the addSeries functions (you can either input a list of Points, x and y, or just y)?

areebg9 avatar Jan 19 '20 23:01 areebg9

Input can be an array of (r,theta) or single r,theta pairs.

KarthikRIyer avatar Jan 20 '20 09:01 KarthikRIyer

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.

KarthikRIyer avatar Jan 20 '20 09:01 KarthikRIyer

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.

areebg9 avatar Jan 23 '20 06:01 areebg9

Could you open a PR with your updated code. I'll take a look.

KarthikRIyer avatar Jan 23 '20 06:01 KarthikRIyer

With the current code (that produces the error)? Or everything without that portion?

areebg9 avatar Jan 23 '20 06:01 areebg9

The complete code with the error.

KarthikRIyer avatar Jan 23 '20 06:01 KarthikRIyer

Ok.

areebg9 avatar Jan 23 '20 06:01 areebg9