Improve the plotting module - sympy/sympy GitHub Wiki

About Me

Basic Information

Name: Malkhan Singh

University: National Institute of Technology, Rourkela

Major: Computer Science and Engineering

Email: [email protected]

GitHub /Gitter: Malkhan52

Blog: malkhan52.github.io

Timezone: IST (UTC +5:30)

Background

I am a second year undergraduate student pursuing Computer Science and Engineering at National Institute of Technology, Rourkela, Odisha India. I have been programming for about 2 years now. I started with C and C++. I've used C++ mainly for competitive programming contests like hekerearth and hearkerrank. I learnt Python last year mainly to use OpenCV. I am also a website development enthusiast. I’m a member of Monday Morning tech team, which is the official student media body of NIT Rourkela where my task is to fix bugs and create new features.

My Projects

Title MM-Summer-Task (linked to GitHub repo)

Details This project was done under the coordination of Monday Morning Coordinator as an induction task. This project was to develop a fully working news-website with backend admin panel using CodeIgniter in PHP framework. I worked on this project in summer of 2017.

Title NITR-IMUNC-2018 (linked to GitHub repo)

Details This project was to develop a theme based website for an event going to held in NIT Rourkela. In this project, all code is provided me with a freely available template theme I only modified its code according to their requirements. I worked on this project in December 2017

In future, I want to work in computer vision and image processing field.

I am quite comfortable using git and GitHub for version control. I am using it since April 2017 for my all projects.

My educational background is sufficient for the project. I have taken the following mathematical courses: Calculus, Probability and Statistics; programming courses: Algorithms, Programming and Data Structures.

My favourite feature of Sympy is its textplot representation. I feel it’s really a cool idea, I didn’t know about this type of plotting before sympy.

Platform details

OS: Window 10

Editor: Sublime Text 3

My favourite editor is sublime text 3, it helps in coding with more number of files as it can refer all used places of a word in the opened folder also you can search a particular word within one or more folders with excluded filter and also can replace all selected word in one go.

Contributions to sympy

Patch:-

(Merged) Correct algorithm of functions named gray_to_bin and bin_to_gray #14468.

Issue:-

#14506 Incorrect plotting of plot_parametric(). In higher order expression this function create some problem. Like to plot Lissajous curves.

plot_parametric_issue_1plot_parametric_issue_2

Contributions to adamantium

(private repo)

Adamantium is the project of Monday Morning’s live website‘s code (A news website). I’m contributing to it since August 2017.

Project Overview

Plotting the solution of equations and system of equations is the most crucial feature of a Computer Algebra System other than solving them. One of the features that place Sympy in a class by itself among similar computer-aided mathematics tools is its advanced graphics capabilities. I would like to mention some graphics features that I love.

Details of Project

Parameters manipulation in graph-module

The main objective of parameters manipulation is to add GUI provided by matplotlib.widgets.

Examples:-

Span Selector:- This will work as a magnifier of graphs with user’s choice. In this there are two windows above one window for the original graph in which user will select the span of the graph and its magnified graph will come in the bottom window. (For code see link in reference)

In[]:plot(expr,(var,0,5,),magnifier=True)

Out[]:

span_selector

Multicursor:- This will help users to compare two graphs. In below image, there are two windows each window has the different graph. So, the user can compare graph with respect to position.(for code see link in reference)

In[]:plot(expr,expr,(var,0,2,),multicursor=True)

Out[]:

multicursor

Cursor:- I think this feature is most important for sympy plotting. This will be the default for all type of plots. This will show two axes (perpendicular to each other) with the position of the cursor in graph window in term of x and y coordinates.(for code see link in reference)

cursor_1

Check-Buttons:- There will be check-boxes equal to the number of expressions or graphs in graph window (each box connected with one graph). This enables to check different combinations of the graph with different expressions in one go. (For the code of this plot see reference)

In[]:plot(expr,expr,expr,(var,0,2,),checkbox=True)

Out[]:

check_box_buttons_1 check_box_buttons_2

Implementation of high level features

(Inspired by Mathematica)

It is provided in projects description “to take inspiration from Mathematica for implementing high-level features in sympy”.

For better understanding, I read a book named “Mathematica Cookbook” written by “Sal Mangano”(only chapter 6 & chapter 7 ). This book helped me to visualize of plotting 2D and 3D. There is a list of features in this book some of them I found useful and impotent for sympy as a CAS tool.

Axes:- some time axes need to suppress, so we can have an optional argument for suppression of axes.

plot(expr,(var,a,b),axes=False)

Mesh:- Mesh will be an option that will allow us to highlight specific points in the plot.(images taken from book)

mesh=all This will highlight all points sampled.

mesh=n This will use n equally spaced points.

mesh_all

FillingStyle:- This will allow us to control colour and opacity of the filling. This will help to visualize inequalities expressions.(images are taken from the book).

filling_axesfilling_05

Polar:- Polar plots are also important in plotting. So for this, there will be an option to enable polar plot inside plot() In issue #14477 @jksuom mentioned possibility of adding polar option same way.

Degree:- To draw the plot with polar coordinates, it would be better to add an option to enable variable in degree.

plot(expr,(var,a,b),polar=True,degree=True)

Grid:- Gridding on plot helps the user to understand curve. Gridding will have two options Automatic or Custom. The number of the grid will be according to limits. Lets limits are min, max then No.of grids = max-min. For custom user can give the number of the grid in given range.

Frame - Subframe:- In order to compare two or more plot we need them in the separate frame. For 2D to compare two plots we can have them in one frame, but for the 3D plot, this will create the problem. So to overcome this problem it would be better to give an option to enable subframe. In Mathematica they have framed as a separate option other than subframe, so for them to enable subframe must have to enable frame. But here we will add the only subframe, so only need to enable subframe in arguments list.

Implementation of an intelligent routine that automatically determines the regions of interest for plotting

Usually, users draw the graph to check nature of curve at following regions:-

  • Near origin.

  • A sudden change in slope.

  • Discontinuity in the curve.

  • Intersection with x-axis or y-axis.

If there is more than one curve then:-

  • The intersection of two or more curves.

So we will find curve’s nature for these points and show that region if exist otherwise default region will be near the origin.

Implementation of the backend for mayavi for 3D plotting

Mayavi has advanced features for 3D plotting. I am new for mayavi so I can not say more about it, but I installed successfully it an tried some examples given in its tutorial. So I felt it has many features which can be implemented in sympy i.e. different view angle with respect to axes, can zoom in-zoom out using the mouse, easily can get contour with the changeable number of contour in GUI window. For API reference of mayavi I read this document page.(see for reference).

Timeline

I have my summer vacations starting from 1st May. I have no other commitments and will be easily able to give 50 - 60 hours a week. My college will restart in end of July but I will still be able to contribute at least 35 - 40 hours since there will be no exams or tests until GSoC period ends. I planned for project period such that I will send the pull request with the period of 4-5 days and rest 2-3 days will work on that PR to make it merge. I will work on features one by one not to mix them together.

I will also maintain a blog so that my mentors can regulate my work, and also monitor my progress.

Pre-GSoC

I already went through some portion of SymPy's code for plotting.I would like to Inspect remaining (pyglet module) part of it.

Since I caught an issue #14506 with plot_parametric() So, will solve it. Because for all the project period we will use this function to add or modify arguments.

Discuss the choice and implementation of the data structures, algorithms, features for GUI with mentors.

At least try to solve the problem with the old pyglet module, so that during GSoC will able to introduce new features in it.

Week 1 & 2

As I noticed in the code for the pyglet-plot module it has many feature and function for plotting, So in order to enhance features of sympy.plotting this module must be in working potions. I decided to work with it first before going further. The pyglet plot also holds geometry module.

  • Symplify and rewrite the backend for pyglet module

Week 3 & 4

Working with 2D plotting is easy to understand and visualize, So I will start introducing these features(new) with 2D:-

  • Cursor
  • Multicursor *Spanselector
  • Checkboxes
  • Degree
  • Polar

This will be the time of First evaluation. Before this, I would like to finish up to this part.

Week 5

Objects from geometry module (I went through this module it provides more information than we need to plot curve):

  • Point, line, circle, ellipse, parabola, polygon, plane.

Week 6, 7 & 8

  • Implement a backend for mayavi for 3D plotting.

  • Introduce contour feature.

  • 3D plot viewing from the different angle.

  • Introduce multi-subframes for more than one 3D plot.

This will be the time of Second evaluation. Before this ‘backend for mayavi’ would be finished.

Week 9 & 10

Implement high-level features inspired from Mathematica:-

  • Axes suppression.
  • Grid (Automatic and Custom)
  • FillingStyle
  • Mesh

Week 11

  • Improve textplot module so that it can support all kinds of plots using ASCII/Unicode characters.

  • Implement an intelligent routine that automatically determines the regions of interest for plotting.

Week 12

  • Random test for all feature of plotting and fix them.
  • Write Documentation of the work done in GSoC Period.

Post GSoC

I would like to continue contributing to SymPy even after my GSoC period.

References

Mathematica Cookbook

Advance use of mayavi for API

Check buttons code

Widget cursor code

Multicursor code

Span Selector code