Presenting newplot.py

A new plotting framework supporting numerous backends.

Two files are present:
plotting/newplot.py containing the module
test.py in the root containing some examples

See the docstring of newplot.py for implementation details.

It has 2d and 3d plots, parametric plots and contours.

Example:

a = Plot(x**2, x, 0, 10)
a.title = 'A Figure'
a.xlabel = 'The argument'

A big and dirty commit.

The current version of matplotlib (1.1.0) has a bug so some
of the 3D stuff does not work.
Concerning the bug - it's reported, but to fix it now try this:
/usr/lib/pymodules/python2.7/mpl_toolkits/mplot3d/axes3d.pyc in set_autoscale_on(self, b)
    252         """
    253         Axes.set_autoscale_on(self, b)
--> 254         self.set_autoscalez_on(self, b)
    255
    256     def set_autoscalez_on(self, b) :

TypeError: set_autoscalez_on() takes exactly 2 arguments (3 given)
I believe there is one self too much.
Adding an experimental new lambdify to the plotting module.

Needed because of the limitation of the old lambdify:
No symbolic Sums or other nontrivial expression.
Mixing translated and non translated functions.

rewrite of lambdify - This stuff is not stable at all.

It is for internal use in the new plotting module.
It may (will! see the Q'n'A below) be rewritten.

  We parse the expression string into a tree that identifies functions. Then
 we translate the names of the functions and we translate also some strings
 that are not names of functions (all this according to translation
 dictionaries).
  If the translation goes to another module (like numpy) the
 module is imported and 'func' is translated to 'module.func'.
  If a function can not be translated, the inner nodes of that part of the
 tree are not translated. So if we have Integral(sqrt(x)), sqrt is not
 translated to np.sqrt and the Integral does not crash.

#  Please, if there is a bug, do not try to fix it here! Rewrite this by using
# the method proposed in the last Q'n'A below.
#  If you insist on fixing it here, look at the workarounds in the function
# sympy_expression_namespace and in lambdify.

# Q: Why are you not using python abstract syntax tree?
# A: Because it is more complicated and not much more powerful in this case.

# Q: What if I have Symbol('sin') or g=Function('f')?
# A: You will break the algorithm. We should use srepr to defend against this?
#  The problem with Symbol('sin') is that it will be printed as 'sin'. The
# parser will distinguish it from the function 'sin' because functions are
# detected thanks to the opening parenthesis, but the lambda expression won't
# understand the difference if we have also the sin function.
# The solution (complicated) is to use srepr and maybe ast.
#  The problem with the g=Function('f') is that it will be printed as 'f' but in
# the global namespace we have only 'g'. But as the same printer is used in the
# constructor of the namespace there will be no problem.

# Q: What if some of the printers are not printing as expected?
# A: The algorithm wont work. You must use srepr for those cases. But even
# srepr may not print well. All problems with printers should be considered
# bugs.

# Q: What about _imp_ functions?
# A: Those are taken care for by evalf.

# Q: Will ast fix all possible problems?
# A: No. You will always have to use some printer. Even srepr may not work in
# some cases. But if the printer does not work, that should be considered a
# bug.

# Q: Is there same way to fix all possible problems?
# A: Probably by constructing our strings ourself by traversing the (func,
# args) tree and creating the namespace at the same time. That actually sounds
# good.
Removing lambdarepr from experimental_lambdify in newplot.py

For the restricted usage of experimental_lambify there is absolutely
no need to complicate the code and make it dependent on lambdarepr.

Now experimental_lambdify is completely self contained.

Also some additions to the documentation were done.
Removing checks for ctypes.

There were checks about the ctypes module. As it's included in
python 2.5+ those are no longer needed.

Also removed a remark about ctypes from the documentation.
Moving the old pyglet plotting module and adding a warning

To make place for the new interface the old plotting module was
moved to another location. It was noted in examples, documentation
and tests.

The location has changed but the Plot function is still imported
from the same location. It's a proxy object giving the Plot from
the old pyglet module, but it adds a warning about the change.
Importing the pyglet Plot from the new location does not give a
warning.
plotting: enabled doctests for some utils.
Adding plot function (not implemented)

The docstring for the plot function is ready. The function itself is not
ready. It just calls Plot with the same arguments.

Also now the default between a contour plot and a 3d plot is the 3d plot.

Also fixed some comments.
Finishing touches in the new plotting module.

There are probably still many bugs, but the module should be ready for
review after this commit.

- Finishing the plot function.
   Now the plot function gives a great flexibility in how one
can define a plot. Multiple cartesian or parametric plots are supported.

- Fixing imports.

- Minor fixes to plotting/experimental_lambdify.py
 The sqrt function was not translated to the numpy sqrt. Now it is.
before the commit sqrt(x) -> sqrt(x).evalf()
after the commit sqrt(x) -> np.sqrt(x)
 Also experimental_lambdify now supports the print_lambda argument.
When true the function will print the lambda expression to the terminal
before creating the actual lambda function.

- Many other clean-ups and bug fixes.
Preparing examples of the new plotting module.

In the root folder two preliminary files with examples were created.
They should be moved.
Bug fixes and examples concerning coloring of plots.
Fixes to experimental_lambdify from the plotting module.
Stop raising warnings every single one missing option in the backend.
Some new functionality for plotting only integer values and steps.
Extensive simplifications of code for the plotting module.

All the setattr and getattr overrides were deleted. The _options and
_aesthetics dicts were deleted and all options and aesthetics are now
regular attributes.
All plotting examples are moved to ./examples
Add a rudimentary save() method to plot.

Currently there is only one argument (string path) that is directly
sent to the backend. No *args or **kwargs.
A multitude of changes concerning the plotting module.

1.
`plot` now handles lists of expressions, Plot objects and Series objects.

Examples of lists of expressions as arguments:
plot([x,x**2]) # with implicit default range
plot([x,x**2], (0,2)) # explicit range
plot([-abs(x*y)-10, abs(x*y)+10], (-5,5), (-5,5)) # 3D surface

Examples of Plot and Series objects as arguments:
a = plot((x,(0,2)), (x**2,(0,2))) # creating a Plot object
plot(a) # Plotting a Plot objects
plot(a[0]) # Plotting a Series object

2.
Extensive changes to experimental_lambdify.

Now there is a smart vectorized_lambdify function that tries to work around
all the problems of lambdifying.

The following translations are tried:
only numpy
    - on FloatingPointError (numpy tried to return a nan):
        take the real part and use complex arguments
    - on AttributeError (meaning that numpy can not uderstand the object)
      or on TypeError (unhashable type) raised by sympy:
        only python math and then vectorize float64
    - on ValueError (Symbolic value, can't compute):
        only python cmath and then vectorize complex128

When using python math/cmath there is no need for evalf or float/complex
because python math/cmath calls those.

This function never tries to mix numpy directly with evalf because numpy
does not understand sympy Float. If this is needed one can use the
float_wrap_evalf/complex_wrap_evalf options of experimental_lambdify or
better one can be explicit about the dtypes that numpy works with.

3.
Refactor the general options in the matplotlib backend.

The sequence of operations was refactored and simplified. Some of the
operations were redoing previous operations and this was not good.

Also a new auto option for axis_center was created as a consequence.
Now the axis do not go out of the viewing window.

4.
Small fix for np.array reshaping in the plotting module.

Resetting the shape attribute was working in numpy 1.5.1 but was raising
AttributeError: incompatible shape for a non-contiguous array
in numpy 1.6.1.

Now the reshape() method is used instead of changing the shape attribute.

5.
Small cosmetic changes
Small fixes to the matplotlib plotting backend.

Removal of a useless `hasattr` call. It is not useful because the if branch
controled by it is never to be executed. Moreover it was spelled
erroneously.

Change the order of operations so the x and y label are actually plotted.
Add ipython notebooks with plotting examples.

The notebooks are not evaluated. That way the png images are not generated
and do not take up place.
matplotlib version check in the plotting module

If the version is less than 1.0.0 matplotlib is not imported and
ascii is used. If the version is less than 1.2.0 (not released yet)
the 3D surface coloring does not work.