Plotting a circle

578 views
Skip to first unread message

Viral Shah

unread,
Dec 3, 2011, 2:35:12 AM12/3/11
to juli...@googlegroups.com
I tried plotting a circle. It comes out looking like an ellipse because the grid spacing is different along x and y axes. If the general range of the x and y axes for the display is about the same, it would be nice to have the same grid spacing.

plot(cos(-pi():0.1:pi()), sin(-pi():0.1:pi()))

-viral

Stephan Boyer

unread,
Dec 3, 2011, 2:57:55 AM12/3/11
to juli...@googlegroups.com
You can specify the window:

plot(cos(-pi():0.1:pi()), sin(-pi():0.1:pi()), -2, 2, -1, 1)

But that is an interesting point.  Hold on...

Stephan Boyer

unread,
Dec 3, 2011, 3:16:55 AM12/3/11
to juli...@googlegroups.com
Alright.  Now plotting a circle like:

plot(cos(-pi():0.1:pi()), sin(-pi():0.1:pi()))

Should give you a circle and not an ellipse.

Viral Shah

unread,
Dec 3, 2011, 3:21:35 AM12/3/11
to juli...@googlegroups.com
Awesome. Is it possible to do the equivalent of Matlab's "hold on", which allows you to plot multiple things on the same plot? I guess that would need supporting multiple colors at least.

BTW, does D3 provides ways to put legends, titles etc?

-viral

Stefan Karpinski

unread,
Dec 3, 2011, 3:25:15 AM12/3/11
to juli...@googlegroups.com
Jeez, you're demanding :-P

Stefan Karpinski

unread,
Dec 3, 2011, 3:25:59 AM12/3/11
to juli...@googlegroups.com
But yes, the fixed aspect ratio as a default is right.

Stephan Boyer

unread,
Dec 3, 2011, 3:31:51 AM12/3/11
to juli...@googlegroups.com
Regarding legends/titles:  D3 is not a plotting library.  It's a graphics library that supports only primitive operations - there are no notions of plots, legends, etc.  Just lines, text, etc.  And this is a good thing because it basically means the answer is "yes," we can do that.

Multiple plots should be pretty easy.  Does anyone else want to try implementing this to get familiar with the graphics/web framework?

Viral Shah

unread,
Dec 3, 2011, 3:37:09 AM12/3/11
to juli...@googlegroups.com
How does the graphics/web framework work? Can you describe how to access a D3 functionality from julia? Perhaps the code should be factored so that an API is exposed, where the low-level stuff is in ui/ and higher-level stuff in j/

I certainly want to jump into it. I am massively procrastinating, just because of how cool the graphics and web-repl stuff is. But, over the next few days, I do want to add stuff to this.

-viral

Stephan Boyer

unread,
Dec 3, 2011, 7:07:26 AM12/3/11
to juli...@googlegroups.com
Alright.  So Julia doesn't have access to any of the D3 stuff.  Instead, Julia basically just sends a message to the client that says ''here are some points to plot," and the browser is responsible for determining what it will look like and how to present it with D3.

There is a message-passing API that Julia uses to talk to the browser (with a webserver sandwiched in the middle but you can pretend like it's not there).  It's implemented in ui/webserver/julia_web_base.j (do a git pull right this second if you haven't already).

But for graphics (and other web repl specific functionality in the future), the implementation of the network stack (julia_web_base.j) can be ignored.  All of the graphics functions are in ui/webserver/julia_web.j, so this is where to go if you want to extend the functionality (we can move it to j/ if that's better -- we just need to make sure it isn't loaded for the non-web repls).

The graphics functions themselves are pretty simple -- all they do is send a __MSG_OUTPUT_PLOT message (all of the variable names in the network stuff star with two underscores to prevent name collisions with user variables -- is there a better way to do this namespacing?) to the browser with the appropriate data.

In index.htm, near the end of the callback function, after the line if (data[id][0] == MSG_OUTPUT_PLOT), you'll find all the D3 plotting code.  D3 has a kinda steep learning curve, so let me know if you want me to explain any of that.  Also there are some plot-related styles at the end of styles.css.

Alan Edelman

unread,
Dec 3, 2011, 7:13:08 AM12/3/11
to juli...@googlegroups.com
Should this be working right now?
I go to 18.111.1.99 and nothing happens

Viral Shah

unread,
Dec 3, 2011, 7:15:54 AM12/3/11
to juli...@googlegroups.com
Go to http://tryjulia.xvm.mit.edu/

Once we fix the julia on beowulf and get things to stabilize a bit, http://www.tryjulia.org/ will always point to the right one.

-viral

Viral Shah

unread,
Dec 3, 2011, 7:24:15 AM12/3/11
to juli...@googlegroups.com
I just saw the plot() code, and see what you are talking about. Easy enough to add other similar stuff, and add a bunch of functionality to plot for multiple vectors, colors. Presumably, things like title, legend, axes notation etc. will also be equally easy.

What would it to take to make use of all that other D3 stuff? If we could do that kind of stuff, we would have something truly cool.

-viral

Stephan Boyer

unread,
Dec 3, 2011, 5:46:45 PM12/3/11
to juli...@googlegroups.com
We should probably change plot() to plot_line() and have plot_scatter(), plot_bar(), plot_scalar_field(), plot_vector_field(), plot_slope_field(), etc.  And for image processing, we should be able to plot bitmaps as well.  I don't know if sound processing is something that we want Julia to be able to do, but with HTML5 we could make it happen =).

D3 can also do some cool animation stuff -- I wonder what we could do with that.

Also, the ability to zoom is probably a good thing to have.

Viral Shah

unread,
Dec 3, 2011, 6:05:38 PM12/3/11
to juli...@googlegroups.com
Let's leave plot() as it is, for familiarity purposes. The rest should be added as you suggest.

-viral

Reply all
Reply to author
Forward
0 new messages