65

C# seems to show some promise for scientific computing, but I found very little about one plotting 2D graphs, which is very important both for science student and scientists.

Is there a reliable, free, way to create publication quality 2D plot with C# ? And the capacity to save to several formats (png, eps, ...). Something similar to Python's matplotlib ?

7 Answers7

59

There is OxyPlot which I recommend. It has packages for WPF, Metro, Silverlight, Windows Forms, Avalonia UI, XWT. Besides graphics it can export to SVG, PDF, Open XML, etc. And it even supports Mono and Xamarin for Android and iOS. It is actively developed too.

There is also a new (at least for me) open source .NET plotting library called Live-Charts. The plots are pretty interactive. Library suports WPF, WinForms and UWP. Xamarin is planned. The design is made towards MV* patterns. But @Paweł Audionysos suggests not such a good performance of Live-Charts WPF.

Jeankowkow
  • 814
  • 13
  • 33
MajesticRa
  • 13,770
  • 12
  • 63
  • 77
  • 1
    I've just tested both libs. Oxyplot API seem bit weird and is not well documented. I've struggled on how to plot simple `float[]` instead of function as showed in example. Live-Charts looks great at the begging. Giffs looks impressive, API looks better, it's well documented, many examples but... The performance of it is unacceptable. It hangs for 20 seconds just to display 4K floats. Even with 400 it's choking a bit :( They offer some paid, faster version that will use DirectX more directly but I don't think ...I know such poor performance is not WPF fault. – Paweł Audionysos Jan 06 '19 at 01:41
  • 1
    I know from my personal experience that WPF is capable of displaying and panning over 100K lines even with my unoptimized code. They must have use WPF primitives like `Line` or something or I don't know but 4K rendered in 800x600 view is just nothing... Event LINQPad `Chart` can render 100K lines in second. Anyway, If you plan to plot few more than couple samples I would recommend the reader to try something else. – Paweł Audionysos Jan 06 '19 at 01:41
  • API: a control has DataModel which contain Axis, Series and other objects. You call Add method of series to add points or use similar methods. You use properties like axis.Title to set... axis title text! I wish other libraries had such a bad API – MajesticRa Jan 07 '19 at 02:40
  • 1
    About performance. I worked with something like 100 millions of points. BTW, Oxiplot has a browser with examples with performance tests. Yes, you have to do some considerations if you have large data, but it is doable and not so complex. – MajesticRa Jan 07 '19 at 02:44
  • 1
    Documentation - look the examples code. Works very good as a documentation. Indeed there are cases that is hard to google. But community answers questions by github issues. It is free library after all. Write the docs, return your debt to community – MajesticRa Jan 07 '19 at 02:48
  • 1
    I didn't say Oxiplot have bad performance but Live-Charts do. Of course you can plot millions points if you optimize the input, I even wrote plotting of whole song wave file with zooming and panning in ActionScript but this requires re-sampling which I expected a plot library to do for me... but even without any special optimization, choking with 4K lines mean something bad is happening in the library. Anyway, after trying few more libraries, I'm currently using Windows Forms `Chart` component which is easy to use and very flexible. Best choice in my opinion if you want a free option. – Paweł Audionysos Jan 08 '19 at 05:13
  • Sorry! Seems I'm to biased towards Oxiplot! Hadn't thought you mean Live-Charts. Made an update – MajesticRa Jan 13 '19 at 23:59
11

ZedGraph is a good choice.

Bob Nadler
  • 2,755
  • 24
  • 20
8

See Samples Environment for Microsoft Chart Controls:

The samples environment for Microsoft Chart Controls for .NET Framework contains over 200 samples for both ASP.NET and Windows Forms. The samples cover every major feature in Chart Controls for .NET Framework. They enable you to see the Chart controls in action as well as use the code as templates for your own web and windows applications.

Seems to be more business oriented, but may be of some value to science students and scientists.

gimel
  • 83,368
  • 10
  • 76
  • 104
4

gnuplot is an actively maintained program widely used in the scientific community. Normally plots are generated from data files which you can write out in your C# program, but it is also possible to call the gnuplot executable from C# and display the generated image in a C# picture box.

Danvil
  • 22,240
  • 19
  • 65
  • 88
  • 3
    Are there any native plotting libraries for C# that are similar to gnuplot? I am a bit hesitant on using something like this when it needs to call other processes. – theGreenCabbage Dec 03 '13 at 15:14
2

I started using the new ASP.NET Chart control a few days ago, and it's absolutely amazing in its capabilities.

Here is the link.

EDIT: This is obviously only if you are using ASP.NET. Not sure about WinForms.

dodexahedron
  • 4,584
  • 1
  • 25
  • 37
BBetances
  • 925
  • 1
  • 14
  • 23
1

I just wanted to supplement MajesticRa's recommendation of OxyPlot, and point out how OxyPlot can be used for a variety of plotting cases. The software is free and Open-Source, very polished, and allows for a variety of uses beyon normal 2D mapping.

I've been using OxyPlot for an unorthodox project, where I display (in WPF/C#) a map (Robotic Occupancy Grid) which I could overlay with LineSeries (Path Traveled) and PointSeries (Way Points). Using the OxyPlot ImageAnnotation feature I am able to display 60Hz Video within my OxyPlot, by periodically updating the ImageAnnotation on its own thread, while mapping Series of points overtop the video. The background video and points are even scalable and translatable.

Hopefully this is helpful for other looking to display plots overtop of images and videos.

CodyF
  • 4,977
  • 3
  • 26
  • 38
0

NPlot is a pretty good simple open source 2D plotting API. Unfortunately, the web site is down. I don't know if this is just temporary or not. I haven't heard of any bad news. It may come back up.

http://www.nplot.com

Here is an article describing it:

https://web.archive.org/web/20210612110405/https://aspnet.4guysfromrolla.com/articles/072507-1.aspx

The previous article uses VB.NET, but obviously this will work with C#.

Again, not sure why nplot's site is not currently working but it is a somewhat popular plotting API that I've used in the past. I post it for your information and in case of the likely event nplot will be back up soon. :)

Edit:

Thanks to a Hosam Aly, it looks like the SourceForge project can still be accessed here:

http://sourceforge.net/projects/nplot

BobbyShaftoe
  • 28,337
  • 7
  • 52
  • 74