Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 615b554

Browse filesBrowse files
committed
add functions to create 2d and 3d plot volumes
1 parent c18ee0e commit 615b554
Copy full SHA for 615b554

File tree

Expand file treeCollapse file tree

1 file changed

+96
-0
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+96
-0
lines changed

‎spatialmath/base/animate.py

Copy file name to clipboardExpand all lines: spatialmath/base/animate.py
+96Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -665,3 +665,99 @@ def set_xlabel(self, *args, **kwargs):
665665

666666
def set_ylabel(self, *args, **kwargs):
667667
self.ax.set_ylabel(*args, **kwargs)
668+
669+
def plotvol2(dim, ax=None):
670+
"""
671+
Create 2D plot area
672+
673+
:param ax: axes of initializer, defaults to new subplot
674+
:type ax: AxesSubplot, optional
675+
:return: initialized axes
676+
:rtype: AxesSubplot
677+
678+
Initialize axes with dimensions given by ``dim`` which can be:
679+
680+
* A (scalar), -A:A x -A:A
681+
* [A,B], A:B x A:B
682+
* [A,B,C,D], A:B x C:D
683+
684+
:seealso: :func:`plotvol3`, :func:`expand_dims`
685+
"""
686+
dims = expand_dims(dim, 2)
687+
if ax is None:
688+
ax = plt.subplot()
689+
ax.axis(dims)
690+
return ax
691+
692+
def plotvol3(dim, ax=None):
693+
"""
694+
Create 3D plot volume
695+
696+
:param ax: axes of initializer, defaults to new subplot
697+
:type ax: Axes3DSubplot, optional
698+
:return: initialized axes
699+
:rtype: Axes3DSubplot
700+
701+
Initialize axes with dimensions given by ``dim`` which can be:
702+
703+
* A (scalar), -A:A x -A:A x -A:A
704+
* [A,B], A:B x A:B x A:B
705+
* [A,B,C,D,E,F], A:B x C:D x E:F
706+
707+
:seealso: :func:`plotvol2`, :func:`expand_dims`
708+
"""
709+
dims = expand_dims(dim, 3)
710+
print(dims)
711+
if ax is None:
712+
ax = plt.subplot(projection='3d')
713+
ax.set_xlim3d(dims[0], dims[1])
714+
ax.set_ylim3d(dims[2], dims[3])
715+
ax.set_zlim3d(dims[4], dims[5])
716+
return ax
717+
718+
def expand_dims(dim=None, nd=2):
719+
"""[summary]
720+
721+
722+
:param dim: [description], defaults to None
723+
:type dim: [type], optional
724+
:param nd: [description], defaults to 2
725+
:type nd: int, optional
726+
:raises ValueError: bad arguments
727+
:return: 2d or 3d dimensions vector
728+
:rtype: ndarray(4) or ndarray(6)
729+
730+
Compute bounding dimensions for plots from shorthand notation.
731+
732+
If ``nd==2``, [xmin, xmax, ymin, ymax]:
733+
* A -> [-A, A, -A, A]
734+
* [A,B] -> [A, B, A, B]
735+
* [A,B,C,D] -> [A, B, C, D]
736+
737+
If ``nd==3``, [xmin, xmax, ymin, ymax, zmin, zmax]:
738+
* A -> [-A, A, -A, A, -A, A]
739+
* [A,B] -> [A, B, A, B, A, B]
740+
* [A,B,C,D,E,F] -> [A, B, C, D, E, F]
741+
"""
742+
dim = base.getvector(dim)
743+
744+
if nd == 2:
745+
if len(dim) == 1:
746+
return np.r_[-dim, dim, -dim, dim]
747+
elif len(dim) == 2:
748+
return np.r_[-dim[0], dim[0], -dim[1], dim[1]]
749+
elif len(dim) == 4:
750+
return dim
751+
else:
752+
raise ValueError('bad dimension specified')
753+
elif nd == 3:
754+
if len(dim) == 1:
755+
return np.r_[-dim, dim, -dim, dim, -dim, dim]
756+
elif len(dim) == 3:
757+
return np.r_[-dim[0], dim[0], -dim[1], dim[1], -dim[2], dim[2]]
758+
elif len(dim) == 6:
759+
return dim
760+
else:
761+
raise ValueError('bad dimension specified')
762+
else:
763+
raise ValueError('nd is 2 or 3')

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.