KarthikRIyer / swiftplot

Swift library for Data Visualization :bar_chart:
Apache License 2.0
399 stars 38 forks source link

Implement new chart type - Polar Plot #39

Open KarthikRIyer opened 4 years ago

KarthikRIyer commented 4 years ago

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:

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

areebg9 commented 4 years ago

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!

KarthikRIyer commented 4 years ago

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

areebg9 commented 4 years ago

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?

KarthikRIyer commented 4 years ago

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?

areebg9 commented 4 years ago

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 notifications@github.com 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 commented 4 years ago
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 commented 4 years ago

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 commented 4 years ago

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

KarthikRIyer commented 4 years ago

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.

areebg9 commented 4 years ago

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 notifications@github.com 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 commented 4 years ago

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 commented 4 years ago

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

KarthikRIyer commented 4 years ago

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

KarthikRIyer commented 4 years ago

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.

areebg9 commented 4 years ago

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.

KarthikRIyer commented 4 years ago

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

areebg9 commented 4 years ago

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

KarthikRIyer commented 4 years ago

The complete code with the error.

areebg9 commented 4 years ago

Ok.