Add asymmetric error bars to scatter plots#316
Conversation
|
Hi @zrolfs Using overload works, but quickly inflates code.
Do not rush to realize this, I think Scott will choose 4 option even better. |
|
Hi @StendProg |
|
I looked more closely at the PR, and didn’t cling to anything, each line expands the functionality and is necessary. limits[1] = xs.Zip(errorXPositive, (x, e) => x + e).Max();
...Not sure if this is easier to read for everyone, but shorter. Additionaly you can add |
|
Hey @zrolfs I haven't taken a look at this yet but it sounds interesting! @StendProg is right, if you add a new demo for this feature it will be a lot easier to assess. Perhaps you can model your demo after this one: by mimicking the class: |
|
Sounds good! I'm busy right now, but I should have time this evening. |
|
I think there's some type of rendering error based on the demo... but before going much farther far down this path, I'm wondering if @zrolfs what do you think? |
|
Oops! I'll take another look. |
Good point... I'm not really sure of a way to do that automatically other than to define the color of the plotted series when you make it, and also define the color of the errorbars when you make that too. An easy way to get those colors is to use this function which returns a pre-defined series of nice-looking colors based on an integer value: var thisColor = new ScottPlot.Config.Colors().GetColor(indexValue);
I think that would be easiest because the "files changed" by this PR as it it is right now is a bit intimidating to review 😅 It would be a lot easier if most of the changes were compartmentalized in a new file. |
|
Thanks for woking on this @zrolfs! Let me know when you think it's ready to merge and I'll take a closer look 👍 |
|
Hi Scott! I think it's ready. |
Thanks @zrolfs I'll take a look! It might take me a day or so, but I'll take it from here and add some modifications/commits to this branch as I go. I'll post an update here when things are looking good to merge! |
|
This is not @zrolfs's fault but there is a GDI rendering glitch where diagonal lines get drawn inappropriately. I ran into this before but I forgot how I solved it... |
No kidding - I'm hitting the same snag! This horizontal offset stuff is super confusing. I'm refactoring the bar plots as part of #315 and they'll be a little smarter about error bars... so I'll try removing the xOffset code from I understand it may break errorbars some of the multi-bar-plot demos, but those are about to be replaced anyway due to #315 so I'm okay with that. |
we can fix it later with ScottPlot#315
make names more consistent with other plottables, favor functions which return values rather than mutate arguments, favor fewer nested statements, remove xOffset
trying to prevent breaking peoples code who might rely on old methods
Yeah! I saw that too! It strangely went away if I didn't touch it for a while... |
| this.yNegativeError = yNegativeError; | ||
| this.capLength = (float)capLength; | ||
| this.xOffSet = xOffSet; | ||
| this.xPositiveError = SanitizeErrors(xPositiveError, xs.Length); |
|
|
||
| // customize the plot to make it look nicer | ||
| plt.Axis(-10, 110, 0, 110); | ||
| plt.Axis(null, null, 0, null); |
There was a problem hiding this comment.
I changed these to help me debug. For WPF, the null defaults made the plots super zoomed in on the first bar. I thought I had screwed up the code until I zoomed out. Just a heads up.
There was a problem hiding this comment.
This might be a bug that just got introduced by #313... I'll take a closer look! Other cookbook have messed up auto-axis suddenly
|
@zrolfs this is looking great! Sorry if I was ambiguous earlier when I suggested having a plottable errorbar would be cool for things like scatter plots and bar plots - my thinking wasn't to remove that functionality from scatters and bars, but rather to provide a secondary (more customizable) way to add scatter plots. A lot of my recent comments were undoing changes to those modules which makes sure this merge won't break anybody's code out there who relies on the existing functionality (and it also makes the PR/merge easier to review because it's fewer files!) I going to keep working on this a bit more, but thought I'd give you an update |
|
Thanks for keeping me posted! I've really appreciated your support and communication. The code base was pretty intuitive and fun to work on, too! If this doesn't get merged by Monday, I'll probably just make a local nuget release for my project, so no rush. |
Probably doesn't have to be fancy. I suspect people will plot errors without plotting things like scatter plots at all. Just errors are useful sometimes, and getting too fancy with the color determination could make that more complex than it needs to be.
so it shows in legend
That's great to hear! It's a lot of work to keep this library minimal and light, but it's worth it because it's so much nicer of a library to work in!
Whatever you're comfortable with. I suspect this will be done by then, but the auto-axis bug that just got introduced in #313 might wind up in there too so you might do well to wait for the "official" one which will be right on its heels. Regarding this PR, we're getting there! Still want to make a few tweaks, but I think this plottable stands nicely on its own EDIT: after fixing GetLimits(): |
previous fix was to call AutoAxis() on the empty plot, but this wasn't good because it didn't get called again automatically when data was added.
HOW TO FIX THE GDI RENDERING GLITCH / NOTE TO FUTURE SCOTT: This GDI rendering glitch only affects small, perfectly level lines drawn with anti-aliasing mode disabled. I fixed this glitch by applying a slight offset to one of the points of the line so it's not perfectly flat. The tilt is invisible to humans, but it fixes the glitch |
|
@zrolfs this looks great! I'm gong to merge and close this PR now. I'll release a new NuGet package later today. Thanks for all your hard work! |





Hi Scott!
I wanted to use asymmetric error bars, so I added in some functionality to allow users to do that. To clarify, this pull request should allow users to:
-create asymmetric error bars
-create only a single (positive or negative) error bar
I used the overloading mechanism so that the methods "PlotScatter" and "PlottableScatter" should still be compatible with previous calls.
Thanks for your consideration with this pull request! I'm happy to answer any questions or make changes if you disagree with something.
Zach