bar plot support for Y offset#476
Conversation
|
Hey @Benny121221, this is an excellent improvement! By adding support for Y offsets you enabled a whole new type of plot type (a waterfall plot). This one-liner is super useful for creating waterfall plots from a series of Y values. double[] yOffsets = Enumerable.Range(0, pointCount).Select(count => ys.Take(count).Sum()).ToArray();What do you think about adding a little function which runs that line under the hood to create the waterfall plot so the user doesn't have to? Something like this (where most of the arguments taken are simply passed to PlotBar): plt.PlotWaterfall(xs, ys);Such a method could accept arguments (preferably not delegates though) to customize coloring, and not require modification of the PlotBar method. Perhaps something like: plt.PlotWaterfall(xs, ys, Color.Green, Color.Red); |
plt.PlotWaterfall(xs, ys);I like it, I am busy today but I'll certainly work on this when i get home or in the coming days. |
Sounds like a plan! |
|
I added your suggestions, it looks like this: The demo code is the following: // generate random data to plot Random rand = new Random(0);
int pointCount = 12;
double[] xs = DataGen.Consecutive(pointCount);
double[] ys = DataGen.RandomNormal(rand, pointCount, 5, 10);
System.Drawing.Color profitColor = System.Drawing.Color.Green;
System.Drawing.Color lossColor = System.Drawing.Color.Red;
string[] monthNames = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
plt.PlotWaterfall(xs, ys, fillColor: profitColor, negativeColor: lossColor);
plt.Title("Y1 Profits");
plt.XLabel("Month");
plt.XTicks(monthNames);
plt.YLabel("Million USD");The |

New contributors should review CONTRIBUTING.md
Purpose:
#463
New functionality (code):
Provide a code example demonstrating new functionality achieved with this pull request (if applicable):
New functionality (image):

Opinion Wanted:
I wonder if
PlottableBarshould take a delegate to decide the colour of the bar, something like this:I photoshopped it to emulate the behaviour:

I like this personally, however this seems niche and could cause trouble for the legend, as one plottable would be multiple colours.
Autoformat your code:
The build will fail if your code is not auto-formatted. Auto-format your code in Visual Studio, or from the console using these commands: