Matplotlib python module, using from C#

Pavel Koryakin
2 min readNov 5, 2016

--

Most of the projects we develop in our company are build up on Windows stack. To be more precise — .NET/C#. There is one disadvantage of .NET which comes up especially in research/data analysis tasks. It is a lack of charting libraries. Or maybe it will be fairer to say that there is a lack of good charting libraries. Good enough to be compared to Python’s matplotlib or Gnuplot. There are plenty of projects, open source and commercial, but from my perspective, they all are either “dead” or being developed from the point of view of someone needs.

So we decided to build up a bridge between C# and Python’s matplotlib. In a few words the approach is this:

  • Create a set of classes both in C# and Python which describe a task (what and how to plot). Let’s call these types a protocol in this post.
  • Create a python script which launches the Flask web-service at localhost and can accept HTTP requests. Primitive “Web-API” with a single method.
  • In C# implement a proxy class which can pass a task (a set of protocol classes) to the Flask app, task serialized in JSON. This C# proxy also launches the Python script if it is not up and running.

That is it. Below are a sample image and a C# code which lies behind. Github repository is here, and there is also Nuget package.

C# code behind the image above

--

--