Repository navigation
[MRG] Optimize 3D display (continued) #11577
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
Changes from 1 commit
2a75026
b168bed
a3c331d
a5c2bd5
e955f56
e227b50
ee53be5
8244c07
677e79b
d095d26
005f6fb
f74f3d7
dda0f82
1c1e4a1
7a5c50d
7c2c22e
b81c118
822f4f7
004fff2
f7795e0
da7f72c
17657a4
e43b930
7211708
5bfa368
5faaa0c
7631cfe
ad0e783
98d1161
1696d52
867819f
92daa11
a268fc7
946b9bc
ff18f5f
76d5dc7
3e230c7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,7 +14,7 @@ | |
| from matplotlib import ( | ||
| artist, cbook, colors as mcolors, lines, text as mtext, path as mpath) | ||
| from matplotlib.collections import ( | ||
| LineCollection, PolyCollection, PatchCollection, | ||
| Collection, LineCollection, PolyCollection, PatchCollection, | ||
| PathCollection) | ||
| from matplotlib.colors import Normalize | ||
| from matplotlib.patches import Patch | ||
|
|
@@ -72,6 +72,26 @@ def get_dir_vector(zdir): | |
| raise ValueError("'x', 'y', 'z', None or vector of length 3 expected") | ||
|
|
||
|
|
||
| def _array_split(arr, indices_or_sections, remove_empty=False): | ||
| """Fix numpy.split to preserve the dimension of empty subarrays. | ||
| """ | ||
|
|
||
| arr_chunks = np.split(arr, indices_or_sections) | ||
|
|
||
| if arr_chunks[-1].size == 0: | ||
|
|
||
| if not remove_empty: | ||
| # Preserve the 2D dimensionality the last chunk that can be empty | ||
| # (numpy <=1.10 replaces empty chunks by a 1D empty array) | ||
| # TODO: The following can be removed when | ||
| # support for numpy <=1.10 is dropped. | ||
| arr_chunks[-1] = np.empty(shape=(0, arr.shape[1]), dtype=arr.dtype) | ||
| else: | ||
| del arr_chunks[-1] | ||
|
|
||
| return arr_chunks | ||
|
|
||
|
|
||
| class Text3D(mtext.Text): | ||
| """ | ||
| Text object with 3D position and direction. | ||
|
|
@@ -245,8 +265,8 @@ def set_segments(self, segments): | |
| self._segments3d_data[:, 3] = 1 | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. #6085 (comment) by @eric-wieser
Done.
Not sure, but I removed the "quaternion" term as suggested. |
||
|
|
||
| # For coveniency, store a view of the array in the original shape | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. typo in "convenience` |
||
| self._segments3d = np.split(self._segments3d_data[:, :3], | ||
| np.cumsum(self._seg_sizes)) | ||
| self._segments3d = _array_split(self._segments3d_data[:, :3], | ||
| np.cumsum(self._seg_sizes)) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| else: | ||
| self._seg_sizes = np.array([]) | ||
|
|
||
|
|
@@ -259,8 +279,8 @@ def do_3d_projection(self, renderer): | |
| if len(self._segments3d) == 0: | ||
| return 1e9 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe the old fixme should stay here, with a comment explaining its for back-compat. I'd be happier with a change to |
||
| xys = proj3d.proj_transform_vec(self._segments3d_data.T, renderer.M).T | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no need for the second transpose. All remaining uses of |
||
| segments_2d = np.split(xys[:, :2], | ||
| np.cumsum(self._seg_sizes)) | ||
| segments_2d = _array_split(xys[:, :2], | ||
| np.cumsum(self._seg_sizes)) | ||
| LineCollection.set_segments(self, segments_2d) | ||
| minz = np.min(xys[:, 2]) | ||
| return minz | ||
|
|
@@ -622,11 +642,10 @@ def do_3d_projection(self, renderer): | |
| self._facecolors3d = self._facecolors | ||
|
|
||
| xys = proj3d.proj_transform_vec(self._vec, renderer.M).T | ||
| xyzlist = [] | ||
| cum_s = 0 | ||
| for s in self._seg_sizes: | ||
| xyzlist.append(xys[cum_s:cum_s + s, :3]) | ||
| cum_s += s | ||
|
|
||
| xyzlist = _array_split(xys[:, :3], | ||
| np.cumsum(self._seg_sizes), | ||
| remove_empty=True) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of |
||
|
|
||
| # This extra fuss is to re-order face / edge colors | ||
| cface = self._facecolors3d | ||
|
|
||
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.
missing "of"