-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
ENH: Optional 3d bar shading #7691
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
ENH: Optional 3d bar shading #7691
Conversation
Current coverage is 62.11% (diff: 100%)@@ master #7691 diff @@
==========================================
Files 174 174
Lines 56022 56024 +2
Methods 0 0
Messages 0 0
Branches 0 0
==========================================
+ Hits 34799 34801 +2
Misses 21223 21223
Partials 0 0
|
907bb0b
to
67d1642
Compare
examples/mplot3d/plot_3d_bars.py
Outdated
# fake data | ||
_x = np.arange(4) | ||
_y = np.arange(5) | ||
_xx, _xx = np.meshgrid(_x, _y) |
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.
typo here, should be _xx, _yy = ...
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.
👍 done
bottom = np.zeros_like(top) | ||
width = depth = 1 | ||
|
||
ax1.bar3d(x, y, bottom, width, depth, top, shade=True) |
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.
simplify to ax1.bar()
instead of ax1.bar3d()
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 understand this one. I'm trying to draw 3-dimensional bars. I thought bar
would draw 2-D bars on the 3D Axes 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.
ah, sorry, my reply apparently never got sent. For Axes3D objects, ax.bar()
is the alias of ax.bar3d()
. The bar3d()
is an anachronism, much like set_xlim3d()
.
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 take it all back. I could have sworn we separated the flat bar stuff out. You are right.
examples/mplot3d/plot_3d_bars.py
Outdated
ax2.bar3d(x, y, bottom, width, depth, top, shade=False) | ||
ax2.set_title('Not Shaded') | ||
|
||
fig.canvas.draw() |
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.
should be plt.show()
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.
👍
lib/mpl_toolkits/mplot3d/axes3d.py
Outdated
"""Generate a 3D barplot. | ||
|
||
This method creates three dimensional barplot where the width, | ||
depth, height, and color of the bars can all ne uniquely set. |
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.
typo: "ne" --> "be"
lib/mpl_toolkits/mplot3d/axes3d.py
Outdated
zsort : str, optional | ||
The z-axis sorting scheme passed onto | ||
:func:`~mpl_toolkits.mplot3d.art3d.Poly3DCollection` | ||
shape : bool, optional |
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.
typo: 'shape' --> 'shade'
x2d, y2d = x2d.ravel(), y2d.ravel() | ||
z = x2d + y2d | ||
ax.bar3d(x2d, y2d, x2d * 0, 1, 1, z, shade=True) | ||
fig.canvas.draw() |
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.
remove the unneeded draw()
remove_text=True, | ||
extensions=['png'] | ||
) | ||
def test_bar3d_dflt_actually3d(): |
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 prefer test names and baseline image names that are the same or very nearly the same. It makes it easy to match a bad image file with the test in the code.
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 enough. I'll change them.
remove_text=True, | ||
extensions=['png'] | ||
) | ||
def test_bar3d_dflt_actually3d_no_shade (): |
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.
extraneous space between function name and parens.
fig = plt.figure() | ||
ax = fig.add_subplot(111, projection='3d') | ||
x = np.arange(4) | ||
y = np.arange(5) | ||
x2d, y2d = np.meshgrid(x, y) | ||
x2d, y2d = x2d.ravel(), y2d.ravel() | ||
z = x2d + y2d | ||
ax.bar3d(x2d, y2d, x2d * 0, 1, 1, z) | ||
ax.bar3d(x2d, y2d, x2d * 0, 1, 1, z, shade=False) | ||
fig.canvas.draw() |
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.
go ahead and take it out here, too
@@ -20,16 +20,37 @@ def test_bar3d(): | ||
ax.bar(xs, ys, zs=z, zdir='y', color=cs, alpha=0.8) | ||
|
||
|
||
@cleanup | ||
def test_bar3d_dflt_smoke(): |
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.
heh... I wonder why this was a smoke test?
67d1642
to
a99c034
Compare
Nope. Look at axes3d.py. You can't do 2d bar() with an Axes3d object. It
overrides the 2d version. The 3d part of many of the methods and attributes
are anachronisms and are only kept for back-compat.
On Jan 1, 2017 5:08 PM, "Paul Hobson" <notifications@github.com> wrote:
*@phobson* commented on this pull request.
------------------------------
In examples/mplot3d/plot_3d_bars.py
<#7691>:
+# setup the figure and axes
+fig = plt.figure(figsize=(8, 3))
+ax1 = fig.add_subplot(121, projection='3d')
+ax2 = fig.add_subplot(122, projection='3d')
+
+# fake data
+_x = np.arange(4)
+_y = np.arange(5)
+_xx, _xx = np.meshgrid(_x, _y)
+x, y = _xx.ravel(), _yy.ravel()
+
+top = x + y
+bottom = np.zeros_like(top)
+width = depth = 1
+
+ax1.bar3d(x, y, bottom, width, depth, top, shade=True)
I don't understand this one. I'm trying to draw 3-dimensional bars. I
thought bar would draw 2-D bars on the 3D Axes object.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#7691>, or mute the thread
<https://github.com/notifications/unsubscribe-auth/AARy-GgAFULsGoScOm_0C4EUa-c00xhhks5rOCP0gaJpZM4LWa0h>
.
|
@WeatherGod Oh, I see. Should I deprecated |
Wait, I take it back, I'll still confused. In axes3d.py, I see: def bar(self, left, height, zs=0, zdir='z', *args, **kwargs):
'''
Add 2D bar(s).
...
''' And then: def bar3d(self, x, y, z, dx, dy, dz, color=None,
zsort='average', shade=True, *args, **kwargs):
"""Generate a 3D barplot.
...
""" These seem like two very different and current methods. In the example that I created I wanted to demonstrate the difference that using shading makes, so 3D bars need to be generated in both cases. The plot looks like this: Perhaps this would be clarified if the example was renamed to |
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.
LGTM 👍
lib/mpl_toolkits/mplot3d/axes3d.py
Outdated
The coordinates of the anchor point of the bars. | ||
|
||
dx, dy, dz : scalar or array-like | ||
The width, depth, and height of the bars, resprectively. |
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.
typo: respectively.
lib/mpl_toolkits/mplot3d/axes3d.py
Outdated
zsort : str, optional | ||
The z-axis sorting scheme passed onto | ||
:func:`~mpl_toolkits.mplot3d.art3d.Poly3DCollection` | ||
shade : bool, optional |
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.
what's the default?
Thanks for the example and the docstring update. It looks great! |
I hadn't seen the previous comments. I can have a look at it if you'd like |
Any chance you will get back to this soon @phobson? |
@QuLogic happy to rebase, but I'm still unclear what @WeatherGod meant with his comments. |
a99c034
to
43bb1c1
Compare
@QuLogic rebased and squashed everything. Despite the name of the example, |
We still have the other things I have noticed to fix, though. |
@WeatherGod understood. I'm looking for clarity on what they might be. |
bb4834c
to
fac8a25
Compare
@WeatherGod oops, sorry. I didn't see your other inline comments 🐑 I took care of them and force-pushed |
fac8a25
to
333e444
Compare
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.
almost there... just noticed a couple more typos and 1 code question.
lib/mpl_toolkits/mplot3d/axes3d.py
Outdated
:func:`~mpl_toolkits.mplot3d.art3d.Poly3DCollection` | ||
shape : bool, optional (default = True) | ||
When true, the dark sides of the bars (relative to the | ||
plot's source of light), shaded. |
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.
typo: shape --> shade
Also, the description is missing a verb. Additionally, I think there is supposed to be a blank line between the zsort entry and the shade entry?
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.
Still missing a verb for this sentence, and possibly a blank line between the zsort entry and the shade entry.
lib/mpl_toolkits/mplot3d/axes3d.py
Outdated
@@ -2511,9 +2536,13 @@ def bar3d(self, x, y, z, dx, dy, dz, color=None, | ||
facecolors = list(mcolors.to_rgba_array(color)) | ||
if len(facecolors) < len(x): | ||
facecolors *= (6 * len(x)) | ||
normals = self._generate_normals(polys) |
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 is this here? wouldn't it make a lot more sense if it was in the if shade
block?
13639c1
to
448e5d7
Compare
Ah, I almost completely forgot... we need a "what's new" entry for this. |
@phobson Do you think you'll have time to write this what's new entry? |
-------------------------------------------- | ||
|
||
A new ``shade`` parameter has been added the 3D bar plotting method. | ||
The default behavior remains to the shade the bars, but now users |
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 think it should be "to shade the bars"
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.
gahhh i read that like 5 times. i'll fix :)
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.
(shakes fist at self)
closes matplotlib#7683 Also expands the testing and documentation of bar3d
397198d
to
a218cb1
Compare
|
||
A new ``shade`` parameter has been added the 3D bar plotting method. | ||
The default behavior remains to shade the bars, but now users | ||
have to the option of setting ``shade`` to ``False``. |
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.
extraneous "to"
a218cb1
to
8e535e6
Compare
ping @WeatherGod |
Closes #7683