The plotting module got merged

27 views
Skip to first unread message

krastano...@gmail.com

unread,
Jun 11, 2012, 4:39:30 PM6/11/12
to sy...@googlegroups.com
Hi all,

The plotting module on which I have been working some time ago got
merged (thanks Chris and thanks to all the reviewers).

A number of ipython notebooks with detailed examples were merged as
well. I have converted them to PDFs so those of you that do not use
ipython-notebook can also consult them. (The formating is bad...)

Plots are implemented as `Plot` objects containing a list of
(Data)`Series` objects. The `Series` objects know what information to
provide to the plotting backend and `Plot` objects know how to operate
on them. `Plot` objects do indeed behave as a list of `Series`
objects. `plot_object[i]` returns the i-th `Series` object, for
instance. There is `Plot.extend` in order to merge two plot objects
and `Plot.append` in order to add a series object.

The attachments:
==============

plot_intro
-------------
= plot_intro describes the module. It explains setting titles,
legends, labels. More importantly it exemplifies all the different
inputs supported by the `plot` function:

=== `plot(expr1, expr2, ... range1, range2, ...)` depending on the
number of expressions, ranges and free variables will plot lines,
parametric lines, 3d parametric lines, surfaces and parametric
surfaces (eg `plot(x*y, (x,0,2), (y,0,2))` will plot a surface and
`plot(sin(u), cos(u), u, (u,0,10))` will plot a 3d parametric line).

=== removing the ranges (eg `plot(x*y, (x,), (y,))`) will use default ranges

=== removing the free variables (eg `plot(x*y, (0,2), (0,2))`) will
detect them automatically

=== removing both ranges and free variables (eg `plot(x*y)` will
detect the variables automatically and use default ranges)

=== using a list of expressions instead of a single expression (eg
`plot([x, x**2], (x, 0, 1))`) will plot them all. This also works if
you remove the range and/or free variable. This works not only for
lines but also for surfaces (eg `plot([x*y, x**2*y], (x,1,2),
(y,1,2))`)

=== `plot` can accept both `Plot` and `Series` objects as arguments


plot_discont
-----------------

= plot_discont shows how this module fails miserably on discontinuous
functions. After this gsoc it is possible that it will work a bit
better (there was already promising work on the adaptive sampling)


plot_gallery
----------------

= plot_gallery shows an amusing example. Please add more *amusing*
examples there.


plot_colors
---------------

= plot_colors explains how to use colors in your graphs. The color
maps are rather arbitrary at the moment (you supply only one scalar
for the color and the module uses its hardcoded colormap)

=== The idea behind coloring (and future aesthetics like width, alpha,
size, etc...) is that you provide a function that is used for
coloring. Depending on its arity different arguments are used. For
instance, if you have created a 3D parametric line you have the
following options:

====== `your_plot.line_color = lambda arg1: f(arg1)` will color using
the function `f` evaluated for the parameter (eg arg1 is the
parameter)

====== `your_plot.line_color = lambda arg1, arg2: f(arg1, arg2)` will
color using `f` evaluated for the x and y coordinates (eg arg1=x,
arg2=y)

====== `your_plot.line_color = lambda arg1, arg2, arg3: f(arg1, arg2,
arg3)` will color using `f` evaluated for the x, y and z coordinates
(eg arg1=x, arg2=y, arg3=z)


plot_advanced
============

Four cool examples:

=== A complicated expression that the previous module was not able to
plot: An integral where the free variable wrt which we plot is in the
limit of the integral.

=== An infinite sum Sum(x**-y, (x, 1, oo)) plot wrt y

=== A plot of a sum, here the interesting thing is that you can use
the option `only_integers=True` in order to plot a staircase.

=== Something that was very cool (poorman's implicit plot for the
magnetization in the Ising model of spins). However due to something
that changed in master it does not work anymore (this is a bug
unrelated to the plotting module that I will report soon). Anyway,
Bharath is working on a solution that is waaaaay cooler as part of
his gsoc project.





Warnings
========

The 3d stuff raises errors if you do NOT use the latest DEV version of
matplotlib (some bugs in their code related to coloring).

There are probably many bugs still present in the code. Any help will
be appreciated (including adding cool examples, feature requests,
documentation or simply testing). Also consider helping with this wiki
page: https://github.com/sympy/sympy/wiki/Plotting-capabilities/


I will also try to make a blog post about this soon.

Thanks for all the help with reviewing this pull request.
Stefan
plot_advanced.pdf
plot_colors.pdf
plot_discont.pdf
plot_gallery.pdf
plot_intro.pdf

Chris Smith

unread,
Jun 11, 2012, 4:47:38 PM6/11/12
to sy...@googlegroups.com
> === removing the free variables (eg `plot(x*y, (0,2), (0,2))`) will
> detect them automatically

This is ambiguous: `plot(x*y,(-1,1),(0,2))` which range is x and which
y? Rather than guess, if the length-2 tuples are not the same I think
an error should be raised.

krastano...@gmail.com

unread,
Jun 11, 2012, 4:54:02 PM6/11/12
to sy...@googlegroups.com
I am not completely sure but I think that I agree. Actually, after
working with all these automatic decisions I come to thing that
removing most of them will not be a bad idea.

Ondřej Čertík

unread,
Jun 11, 2012, 4:54:29 PM6/11/12
to sy...@googlegroups.com
That's right. The "blessed" (=documented, encouraged, ...) syntax should be:

p = plot(x**2*y, (x, -5, 5), (y, -1, 1))

but that works too, I just tried.

I played with the new functionality and it works great!

Thanks so much for making this happen, it was badly needed.

Ondrej

Matthew Rocklin

unread,
Jun 11, 2012, 5:02:16 PM6/11/12
to sy...@googlegroups.com
This is awesome. 

I suspect now that the major PR is in master development on this module can happen in a more distributed manner.



--
You received this message because you are subscribed to the Google Groups "sympy" group.
To post to this group, send email to sy...@googlegroups.com.
To unsubscribe from this group, send email to sympy+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/sympy?hl=en.


krastano...@gmail.com

unread,
Jun 11, 2012, 5:05:59 PM6/11/12
to sy...@googlegroups.com
> I suspect now that the major PR is in master development on this module can
> happen in a more distributed manner.

Maybe it will be a good idea if someone cuts the big plot.py file in
smaller ones in order to prevent merge conflicts.

krastano...@gmail.com

unread,
Jun 11, 2012, 5:56:05 PM6/11/12
to sy...@googlegroups.com
By the way, the matplotlib team will soon be making a release so the
problem with 3d plots will be fixed.

http://sourceforge.net/projects/matplotlib/files/matplotlib/matplotlib-1.1.1/

Aaron Meurer

unread,
Jun 11, 2012, 6:40:05 PM6/11/12
to sy...@googlegroups.com
Git doesn't care if content is in one file or in separate files, so I
wouldn't split the file simply for its sake. Of course, unwieldy
files are harder for us humans to navigate, so there are other reasons
to do it as well.

Aaron Meurer

On Jun 11, 2012, at 3:06 PM, "krastano...@gmail.com"

Julien Rioux

unread,
Jun 12, 2012, 3:43:48 AM6/12/12
to sympy
On Jun 11, 10:39 pm, "krastanov.ste...@gmail.com"
<krastanov.ste...@gmail.com> wrote:
> Hi all,
>
> The plotting module on which I have been working some time ago got
> merged (thanks Chris and thanks to all the reviewers).

Congratulations!

But, pulling this in from the main repo brought a test failure on my
machine:

running ./bin/test jscode
===================================== test process starts
======================================
executable: /usr/bin/python (2.7.2-final-0)
architecture: 64-bit
cache: yes
ground types: python
random seed: 34720127

sympy/printing/tests/
test_jscode.py[21] .............E.......
[FAIL]

________________________________________________________________________________________________
___________________ sympy/printing/tests/
test_jscode.py:test_jscode_settings ___________________
File "/home/jacobi/git/sympy-jrioux/sympy/printing/tests/
test_jscode.py", line 108, in test_jscode_settings
raises(TypeError, 'jscode(sin(x),method="garbage")')
File "/home/jacobi/git/sympy-jrioux/sympy/utilities/pytest.py", line
82, in raises
'\'raises(xxx, "code")\' has been phased out; '
TypeError: 'raises(xxx, "code")' has been phased out; change
'raises(xxx, "expression")' to 'raises(xxx, lambda: expression)',
'raises(xxx, "statement")' to 'with raises(xxx): statement'

=================== tests finished: 20 passed, 1 exceptions, in 0.11
seconds ===================
DO *NOT* COMMIT!
Bisecting: 0 revisions left to test after this (roughly 0 steps)
[ff9f5bc4e222ca65453fb98c9f73799e9e3be547] jscode (javascript) printer
added added jscode.py to sympy/printing added test_jscode.py to sympy/
printing/tests to test jscode.py modified __init__.py files to pull in
relevant jscode for imports
running ./bin/test jscode
===================================== test process starts
======================================
executable: /usr/bin/python (2.7.2-final-0)
architecture: 64-bit
cache: yes
ground types: python
random seed: 85311824

sympy/printing/tests/
test_jscode.py[21] .....................
[OK]

========================== tests finished: 21 passed, in 0.10 seconds
==========================
e98dac78aaeb1ab63c026e541246db46940db831 is the first bad commit

krastano...@gmail.com

unread,
Jun 12, 2012, 4:03:28 AM6/12/12
to sy...@googlegroups.com
There are 3 tests failures in master at the moment:

2.5-3.2: a test in jscode that was ok the last time that it was
tested, however master has changed just before the merge of jscode. I
will send a pull request with a fix in a few minutes.

2.7: a test in the plotting module. This test will not run unless you
have installed the dev version of matplotlib. You can merge this
PR1345 in order to fix it. I am waiting for a green flag to merge it
in master.

3.2: a failure in some quantum stuff related to the random number
generator changes in python

krastano...@gmail.com

unread,
Jun 12, 2012, 6:15:47 AM6/12/12
to sy...@googlegroups.com
> There are 3 tests failures in master at the moment:
>
> 2.5-3.2: a test in jscode that was ok the last time that it was
> tested, however master has changed just before the merge of jscode. I
> will send a pull request with a fix in a few minutes.
Was introduced when merging the jscode generator (my bad not to check
for changes in master). It is fixed now.


> 2.7: a test in the plotting module. This test will not run unless you
> have installed the dev version of matplotlib. You can merge this
> PR1345 in order to fix it. I am waiting for a green flag to merge it
> in master.
It is commented out now. Anyway, only my machine actually tests this
at the moment (unless you have the dev version of matplotlib
installed)


> 3.2: a failure in some quantum stuff related to the random number
> generator changes in python
Still a problem.

Chris Smith

unread,
Jun 12, 2012, 6:25:03 AM6/12/12
to sy...@googlegroups.com
>> 3.2: a failure in some quantum stuff related to the random number
>> generator changes in python
> Still a problem.

4 solutions are proposed in http://code.google.com/p/sympy/issues/detail?id=3282

Chris Smith

unread,
Jun 15, 2012, 3:51:05 AM6/15/12
to sy...@googlegroups.com
BTW, you have a note about the ugly code to replace when we drop 2.5.
For it you could use set_union from core.compatibility. (There is a
set_intersection implemented there, too, and use of them will lead to
self-updating code wherever they are used instead of writting the hack
like you did.)

/c

krastano...@gmail.com

unread,
Jun 15, 2012, 4:04:00 AM6/15/12
to sy...@googlegroups.com
Oh, great. I meant to check for something like this in compatibility,
however I completely forgot. I will review you pull request today, and
after it is in I will make a small pull request with the change.

Chris Smith

unread,
Jun 15, 2012, 4:46:46 AM6/15/12
to sy...@googlegroups.com
I'll just make it part of that request. And I'm about to disappear of
the radar for a while as I will be traveling to (and then around) the
US for the next month.
Reply all
Reply to author
Forward
0 new messages