-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP: Error bars 1D plots #247
base: master
Are you sure you want to change the base?
Conversation
Testing script#!/usr/bin/env python
import vcs
import numpy
import MV2
x = vcs.init()
yx = x.createyxvsx()
data = """-11.14902417 -9.17390922 -7.29515002
-7.51774549 -8.63608171
-10.4827395 -9.93859485 -7.3394366 -5.39241468 -5.74825567
-6.74967902 -7.09622319 -5.93836983 -4.04592997 -2.65591499
-1.68180032 -0.86935245 -0.40114047 -0.54273785 -1.36178957
-2.67488251 -3.87524401 -4.84708491 -5.49186142 -5.28618944
-4.30557389 -2.89804038 -1.53825408 -1.84771029 -2.74948361
-2.23517037 -1.73306118 -0.71200646 0.76416785 1.51511193
-0.04018418 -1.54564706 -1.88664877 -0.43751604 0.89988184
0.33437949 -1.70341844 -3.79880014 -4.03570169 -4.7740073
-5.04626101 -3.77609961 -3.18667176 -2.21038272 -1.3666902
-0.54267951 -0.16472441 -0.52871418 -0.83520848 -0.90315403
-0.21747426 0.01922666 0.89621996 1.75691927 3.12657503
4.55749531 6.04921304 7.20744489 7.65294958""".split()
data = numpy.array(data, dtype=numpy.float)
data = MV2.array(data)
yx.datawc_x1 = 0
yx.datawc_x2 = 80
yx.datawc_y1 = -12
yx.datawc_y2 = 12
yx.marker = 'dot'
yx.markersize = 5
eb = x.createerrorbars() # Instantiate error bars definition class
eb.color = [10, 40, 60, 25] # RGBA color
eb.type = "y" # Vertical error bars
yx.errorbars = eb # Set the errorbars on the line plot
error = numpy.random.rand(1, 64) # Create the error array
error = error.tolist()[0]
x.plot(data, yx, error=error) # Pass the error array to the plot function
x.interact()
# x.png('error_bars.png') Result |
@sankhesh I feel it shouldn't be yet another graphic method, but just an option on 1d plots. We had an issue describing this earlier. The bare bones would be something like this: import vcs
gm = vcs.create1d()
gm.errorbars = 'y' # option x,y,xy,None (default None) then you would pass another 1d array for the errors length data = numpy.arange(10)
ebar = numpy.arange(10)/10.
x=vcs.init()
x.plot(data,ebar,gm) In case of xy ebar would be 2D (N,2) In case of x and y only if both side are not the same length here again pass a (N,2) array in case of xy with different length in all direction, pass a (N,4) array. |
@aashish24 @danlipsa @sankhesh I was under the impression we had to wait for opengl2 for this one. |
@sankhesh this looks like a great start.. It would be nice to be able to control the error bars (colours, styles etc), and the line plot (thickness, style, colour) too.. |
@doutriaux1 I see what you mean about not adding another graphics method. I added an additional class to be able to customize the different options of error bars in the future. It seemed intuitive to me that the user can just call
@durack1 Thats the point for the new class. Mid-way through this work, I found Matplotlib ErrorBars which seems a better and cleaner API. If we adopt that way, users can draw error bars without the actual line plot too (useful, maybe). Thoughts? |
@doutriaux1 Switching the OpenGL2 / context2D would change the internal implementation but the API would still be relevant. |
@sankhesh with @durack1 maybe it's better to make your class an attribute of the 1d method gm.errorbars.type = 'xy'
gm.errorbars.linecolor = 'red'
gm.errorbars.linestyle = 'dot'
gm.errorbars.linewidth=2.
gm.errorbars.markertype= 'bar'
gm.errorbars.markercolor = 'red'
gm.errorbars.markerwidth=2.
etc... |
not really, as described above you can still plot this by passing 2 arrays, the 1d data and the erorrs bars length data. With the second array potentially dimensioned (N,4) (for your last case) or (N,2) (see above) |
@@ -289,7 +292,7 @@ def issecondaryobject(sobj): | |||
return 1 | |||
elif (isinstance(sobj, textcombined.Tc)): | |||
return 1 | |||
elif (isinstance(sobj, marker.Tm)): | |||
elif (isinstance(sobj, errorbars.Te)): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks like you lost marker.Tm
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On purpose. It was a duplicate.
@doutriaux1 I see. Yes, its possible that way. And one can set the line opacity/visibility to 0 so that only error bars are visible. I'll wait for @aashish24 and @danlipsa to comment to ensure we have a consensus before I change the API. |
Initial API and working implementation for X and Y error bars on 1D plots.