-
Notifications
You must be signed in to change notification settings - Fork 236
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
fix: extra quote + enh: control over line visibility #72
fix: extra quote + enh: control over line visibility #72
Conversation
Changes Unknown when pulling 93e3f18 on satra:enh/line-visibility-control into ** on maartenbreddels:master**. |
Changes Unknown when pulling 8a94290 on satra:enh/line-visibility-control into ** on maartenbreddels:master**. |
@maartenbreddels - it would be awesome if you can review/merge this. the pattern itself can be extended to the other plot routines. we are trying to simultaneously work on a set of domain specific widgets that depends on this. |
Hi Satrajit, thanks for your contributions. What about making this arguments to plot()? cheers. Maarten |
@maartenbreddels - it seems like a decision as to where to bring up all these arguments. so if every another option is to call |
I think every property of Scatter that makes sense for a function in pylab should be an argument, and kwargs should be used for something that doesn't make sense, but that you may want to set anyway. What would renaming scatter_kwargs to kwargs do, can you explain the issue? |
@maartenbreddels - i updated it i think to reflect what you are saying. however, i also made some changes to the other scatter wrapper functions. mostly this has to do with consistency rather than domain conventions. |
if domain conventions should be used, for-example marker instead of geo, perhaps the signature of scatter should be updated? i have no strong feelings either way on this. |
Great work. I don't think the argument have to match one-to-one match what is in Scatter, but if they are useful the should be exposed. I'll give some feedback on the PR, that will make it clearer maybe I mean, great work 👍 |
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.
So the main question I have is whether we should have plot and scatter have the same argument, but different defaults, what do you think?
ipyvolume/pylab.py
Outdated
@@ -367,12 +367,12 @@ def plot(x, y, z, color=default_color, visible_lines=True, color_selected=None, | |||
:param y: {y} | |||
:param z: {z} | |||
:param color: {color} | |||
:param visible_lines: {visible_lines} |
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.
I'd only expose 'visible'.
ipyvolume/pylab.py
Outdated
@@ -367,12 +367,12 @@ def plot(x, y, z, color=default_color, visible_lines=True, color_selected=None, | |||
:param y: {y} | |||
:param z: {z} | |||
:param color: {color} | |||
:param visible_lines: {visible_lines} | |||
:param color_selected: {color_selected} |
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.
This arg would only make sense for scatter, unless we want plot and scatter to have the same arguments but different defaults, that may not be such a bad idea actually.
ipyvolume/pylab.py
Outdated
@@ -402,7 +402,7 @@ def scatter(x, y, z, color=default_color, size=default_size, | |||
:param size: {size} | |||
:param size_selected: like size, but for selected glyphs | |||
:param color_selected: like color, but for selected glyphs | |||
:param geo: {geo} Uses marker |
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.
I'd say marker, in the Scatter widget I may also change this to marker.
ipyvolume/pylab.py
Outdated
:param vx: {x_dir} | ||
:param vy: {y_dir} | ||
:param vz: {z_dir} | ||
:param vx: x_dir |
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.
u,v,w is more consistent with matlab https://nl.mathworks.com/help/matlab/ref/quiver3.html and matplotlib https://matplotlib.org/mpl_toolkits/mplot3d/tutorial.html#line-plots
kind of. perhaps the other way to state it is: any argument of scatter that is set by plot/quiver/scatter should be exposed as a specific keyword in the definition of plot/quiver/scatter otherwise they cannot be modified by the user using kwargs. i originally ran into it since i wanted to turn visibility off, i was drawing 5000+ lines of different lengths and the update was really slow. i reverted some of those matlab/matplotlib names for now. i think it would be good to make scatter consistent with it. |
…ty-control * upstream/master: Extra " removed
Can you explain this, I'm not sure I follow you. Any argument not exposed by plot can simply be picked up by kwargs and passed on right? |
@maartenbreddels - sorry this must have skipped my notification
not if that arg is defined as a separate keyword arg in the inner func. the reason pull-request is in place is because i was trying to set hence the two options are to always expose any settable keyword that can be manipulated at both levels, but default it in the outer level. hope that makes sense. def inner_func(a=1, b=2, c=3):
pass
def outer_func(**kwargs):
inner_func(a=2, **kwargs)
outer_func(a=3) results in:
|
@maartenbreddels - just a ping here in case you didn't get a chance to look at my response. |
…ty-control * upstream/master: Update README.md fix: plot_isosurface was calling marching cubes twice, and better steps for sliders support for jupyter lab 0.27
Ok, I understand the issue better. def plot(x, y, z, color='red', **kwargs):
defaults = dict(connected=True, visible_markers=False)
kwargs = dict(defaults, **kwargs) # merge dicts, where kwargs get preference over defaults
scatter = Scatter(x, y, z, color=color, **kwargs) So the different defaults (the ones that make sense to hide, such as connected and visible_markers are kind of hidden, but possible to override. |
@maartenbreddels - ah that was the previous proposal :) see this deleted version here: 782aec3#diff-f865c2c721a2719a6169fd34dfb51bc5L373 i'm happy to change it back to that state. |
@maartenbreddels - made the adjustments. |
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.
Excellent 👍 , thanks for putting in unittests as well. Some minor comments, hope you don't mind the endless dragging, but I'd like to get this right.
ipyvolume/pylab.py
Outdated
defaults = dict(visible_lines=True, color_selected=None, size_selected=1, | ||
size=1, connected=True, visible_markers=False) | ||
kwargs = dict(defaults, **kwargs) | ||
scatter_hdl = ipv.Scatter(x=x, y=y, z=z, color=color, **kwargs) |
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.
Why rename do scatter_hdl? I don't know what hdl means.
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.
two reasons -
- while it technically works there is a name clash,
scatter
is a method as well. so there is a local vs global clash that i do not like. _hdl
stands for "handle" since it's really a pointer to the object.
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.
fair point, but I don't abrvs that aren't std ;). I'd rather see s = ipv.Scatter(..), and for python it's always by reference so _hdl doesn't add information, except indeed preventing a possible name collision. my preference goes to s
or scatter_object
ipyvolume/pylab.py
Outdated
@@ -389,20 +392,26 @@ def scatter(x, y, z, color=default_color, size=default_size, size_selected=defau | |||
:param size: {size} | |||
:param size_selected: like size, but for selected glyphs | |||
:param color_selected: like color, but for selected glyphs | |||
:param marker: {marker} | |||
:param marker: Uses marker |
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.
Why replace this docstring (which is substituted by the snippets on top) by this?
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.
sorry that's part of an older segment of changes - will revert that
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.
👍
ipyvolume/pylab.py
Outdated
size_selected=size_selected, geo=marker, selection=selection, **kwargs) | ||
fig.scatters = fig.scatters + [scatter] | ||
return scatter | ||
if 'geo' in kwargs: |
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.
'geo' is used for the Scatter object, but I think marker is a better name, and for this API i chose marker, which is taking it's role.
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.
So I'd remove this part, and simply use marker.
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.
since under the current formulation, kwargs
go on to the scatter call, if someone does use geo
it will result in a clash, since marker
gets converted to geo
. this simply says if some puts in geo
it will overwrite marker
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.
Lets us remove this, and change to use geo->marker (or leave that for me to do)
ipyvolume/pylab.py
Outdated
if 'geo' in kwargs: | ||
marker = kwargs['geo'] | ||
del kwargs['geo'] | ||
scatter_hdl = ipv.Scatter(x=x, y=y, z=z, color=color, size=size, |
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.
Same applies here, why hdl?
|
||
@_docsubst | ||
def quiver(x, y, z, u, v, w, size=default_size * 10, size_selected=default_size_selected * 10, color=default_color, | ||
def quiver(x, y, z, u, v, w, size=default_size * 10, | ||
size_selected=default_size_selected * 10, color=default_color, |
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.
I should be running flake8 :)
ipyvolume/pylab.py
Outdated
return scatter | ||
if 'geo' in kwargs: | ||
marker = kwargs['geo'] | ||
del kwargs['geo'] |
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.
Same here, please just use marker and forget about geo. I think maybe we should change Scatter.geo to Scatter.marker.
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.
if you changed Scatter.geo to Scatter.marker we can simplify some of this.
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.
👍
ipyvolume/pylab.py
Outdated
marker = kwargs['geo'] | ||
del kwargs['geo'] | ||
if 'vx' in kwargs or 'vy' in kwargs or 'vz' in kwargs: | ||
raise KeyError('Please use u, v, w instead of vx, vy, vz') |
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.
I don't think this should be added, quiver had never vx etc as arguments, is we were doing some backward incompatible tricks this would make sense though.
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.
same reasoning as before:
quiver(..., u=u, ..., vx=u)
would be legal but bad. this just raises an exception to notify the user. all of this stems from the fact that any kwargs
eventually gets passed to the lowest level scatter call.
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.
good point, indeed!
ipyvolume/pylab.py
Outdated
del kwargs['geo'] | ||
if 'vx' in kwargs or 'vy' in kwargs or 'vz' in kwargs: | ||
raise KeyError('Please use u, v, w instead of vx, vy, vz') | ||
scatter_hdl = ipv.Scatter(x=x, y=y, z=z, vx=u, vy=v, vz=w, |
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.
Here as well, please remove the _hdl suffix.
@maartenbreddels - updated, if things look you can merge and then do the marker/geo bit. i'll be offline for a bit. |
Excellent, thanks a lot, and thanks for your patience! 👍 |
No description provided.