Skip to content
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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

sankhesh
Copy link
Contributor

@sankhesh sankhesh commented Sep 6, 2017

Initial API and working implementation for X and Y error bars on 1D plots.

@sankhesh sankhesh self-assigned this Sep 6, 2017
@sankhesh sankhesh changed the title Error bars 1D plots WIP: Error bars 1D plots Sep 6, 2017
@sankhesh
Copy link
Contributor Author

sankhesh commented Sep 6, 2017

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

error_bars

@doutriaux1
Copy link
Contributor

@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.

@doutriaux1
Copy link
Contributor

@durack1 @lee1043 feel free to chime on this one.

@doutriaux1
Copy link
Contributor

@aashish24 @danlipsa @sankhesh I was under the impression we had to wait for opengl2 for this one.

@durack1
Copy link
Member

durack1 commented Sep 6, 2017

@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..

@sankhesh
Copy link
Contributor Author

sankhesh commented Sep 6, 2017

@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 canvas.createerrorbars to create the class for customizing the error bars. It is a start and as of now, the options are type: x, y and color.

@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..

@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?

@sankhesh
Copy link
Contributor Author

sankhesh commented Sep 6, 2017

@aashish24 @danlipsa @sankhesh I was under the impression we had to wait for opengl2 for this one.

@doutriaux1 Switching the OpenGL2 / context2D would change the internal implementation but the API would still be relevant.

@doutriaux1
Copy link
Contributor

@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...

@sankhesh
Copy link
Contributor Author

sankhesh commented Sep 6, 2017

Sure, but then can you draw plots like

MatplotlibError

IMHO, that's only possible with a new graphics method (Te, in this case) , right?

@doutriaux1
Copy link
Contributor

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)):
Copy link
Contributor

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

Copy link
Contributor Author

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.

@sankhesh
Copy link
Contributor Author

sankhesh commented Sep 6, 2017

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants