Plotting with C# [closed]
Asked Answered
M

7

66

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 ?

Mcloughlin answered 15/2, 2009 at 5:28 Comment(1)
So where does one actually go for recommendations on books, tools, and software libraries?Tepid
T
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.

Tungting answered 29/11, 2012 at 16:42 Comment(7)
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.Blank
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.Blank
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 APITungting
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.Tungting
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 communityTungting
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.Blank
Sorry! Seems I'm to biased towards Oxiplot! Hadn't thought you mean Live-Charts. Made an updateTungting
A
11

ZedGraph is a good choice.

Autogenesis answered 15/2, 2009 at 5:56 Comment(3)
I've also had success with ZedGraph for smaller applicationsHassiehassin
ZedGraph is really good for smaller applications.Sundew
Is it me, or is ZedGraph ugly? Am I missing the options that make it look nice?Ultrasonics
K
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.

Kiki answered 15/2, 2009 at 6:6 Comment(1)
The link is dead. Is there still some documentation on this or is this project dead?Ranjiv
C
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.

Creeper answered 29/8, 2010 at 0:25 Comment(1)
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.Botulin
U
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.

Unseal answered 15/2, 2009 at 5:46 Comment(2)
It was on there before the edit I think.Vivienviviene
Info can be found at: weblogs.asp.net/scottgu/archive/2008/11/24/…Copywriter
I
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.

Ilion answered 8/5, 2015 at 12:47 Comment(0)
V
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

Vivienviviene answered 15/2, 2009 at 5:52 Comment(1)
You can still open the project's page in SourceForge: sourceforge.net/projects/nplotBarbershop

© 2022 - 2024 — McMap. All rights reserved.