Skip to content

Commit 7f14246

Browse files
committed
- Found and fixed some bugs.
- Added a legend. - Added a label attribute to each plot for the legend. - Added some more tests. - Trying to clean up the mess that is all the internals. - Added cmaps. - Promoted some parameters to properties so they can be modified after inital plot. - Moved around some scalar stuff to try and make the API more consistent.
1 parent b2c572e commit 7f14246

28 files changed

+1530
-600
lines changed

docs/source/Extras.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,24 @@ vtkplotlib.zip_axes
88
.. autofunction:: vtkplotlib.nuts_and_bolts.zip_axes
99

1010

11+
---------------------
12+
1113
vtkplotlib.unzip_axes
1214
---------------------
1315

1416
.. autofunction:: vtkplotlib.nuts_and_bolts.unzip_axes
1517

1618

19+
---------------------
20+
1721
vtkplotlib.TextureMap
1822
---------------------
1923

2024
.. autoclass:: vtkplotlib.colors.TextureMap
2125

2226

27+
--------------------------
28+
2329
vtkplotlib.quick_test_plot
2430
--------------------------
2531

docs/source/Figures.rst

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,73 +21,95 @@ use any. The figure is shown using ``vpl.show()`` or ``fig.show()``. After the
2121
shown figure is closed the current working figure is deleted.
2222

2323

24+
---------------
2425

2526
vtkplotlib.show
2627
---------------
2728

2829
.. autofunction:: vtkplotlib.figures.figure_manager.show
2930

31+
-----------------
3032

3133
vtkplotlib.figure
3234
-----------------
3335

3436
.. autoclass:: vtkplotlib.figures.figure.Figure
3537

3638

39+
--------------
40+
3741
vtkplotlib.gcf
3842
--------------
3943

4044
.. autofunction:: vtkplotlib.figures.figure_manager.gcf
4145

4246

47+
--------------
48+
4349
vtkplotlib.scf
4450
--------------
4551

4652
.. autofunction:: vtkplotlib.figures.figure_manager.scf
4753

4854

55+
-----------------------
56+
4957
vtkplotlib.reset_camera
5058
-----------------------
5159

5260
.. autofunction:: vtkplotlib.figures.figure_manager.reset_camera
5361

5462

63+
-------------------
64+
5565
vtkplotlib.save_fig
5666
-------------------
5767

5868
.. autofunction:: vtkplotlib.figures.figure_manager.save_fig
5969

6070

71+
---------------
72+
6173
vtkplotlib.view
6274
---------------
6375

6476
.. autofunction:: vtkplotlib.figures.figure_manager.view
6577

6678

79+
----------------
80+
6781
vtkplotlib.close
6882
----------------
6983

7084
.. autofunction:: vtkplotlib.figures.figure_manager.close
7185

7286

87+
-------------------------
88+
7389
vtkplotlib.figure_history
7490
-------------------------
7591

7692
.. autodata:: vtkplotlib._history.figure_history
7793

7894

95+
----------------------
96+
7997
vtkplotlib.auto_figure
80-
-----------------------
98+
----------------------
8199

82100
.. autofunction:: vtkplotlib.figures.figure_manager.auto_figure
83101

84102

103+
-------------------
104+
85105
vtkplotlib.QtFigure
86106
-------------------
87107

88108
.. autoclass:: vtkplotlib.figures.QtFigure.QtFigure
89109

90110

111+
--------------------
112+
91113
vtkplotlib.QtFigure2
92114
--------------------
93115

docs/source/Plots.rst

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,81 +2,112 @@ vtkplotlib Plots
22
================
33

44

5+
56
vtkplotlib.scatter
67
------------------
78

89
.. autofunction:: vtkplotlib.plots.Scatter.scatter
910

1011

12+
---------------
13+
1114
vtkplotlib.plot
1215
---------------
1316

1417
.. autoclass:: vtkplotlib.plots.Lines.Lines
1518

1619

20+
--------------------
21+
1722
vtkplotlib.mesh_plot
1823
--------------------
1924

2025
.. autoclass:: vtkplotlib.plots.MeshPlot.MeshPlot
2126

2227

28+
--------------------------------------
29+
2330
vtkplotlib.mesh_plot_with_edge_scalars
2431
--------------------------------------
2532

2633
.. autofunction:: vtkplotlib.plots.MeshPlot.mesh_plot_with_edge_scalars
2734

2835

36+
------------------
37+
2938
vtkplotlib.polygon
3039
------------------
3140

3241
.. autoclass:: vtkplotlib.plots.Polygon.Polygon
3342

3443

44+
---------------------
45+
3546
vtkplotlib.scalar_bar
3647
---------------------
3748

3849
.. autoclass:: vtkplotlib.plots.ScalarBar.ScalarBar
3950

4051

52+
----------------
53+
4154
vtkplotlib.arrow
4255
----------------
4356

4457
.. autofunction:: vtkplotlib.plots.Arrow.arrow
4558

4659

60+
-----------------
61+
4762
vtkplotlib.quiver
4863
-----------------
4964

5065
.. autofunction:: vtkplotlib.plots.Arrow.quiver
5166

5267

68+
---------------
69+
5370
vtkplotlib.text
5471
---------------
5572

5673
.. autoclass:: vtkplotlib.plots.Text.Text
5774

5875

76+
-----------------
77+
5978
vtkplotlib.text3d
6079
-----------------
6180

6281
.. autoclass:: vtkplotlib.plots.Text3D.Text3D
6382

6483

84+
-------------------
85+
6586
vtkplotlib.annotate
6687
-------------------
6788

6889
.. autofunction:: vtkplotlib.plots.Text3D.annotate
6990

7091

92+
------------------
93+
7194
vtkplotlib.surface
7295
------------------
7396

7497
.. autoclass:: vtkplotlib.plots.Surface.Surface
7598

7699

100+
-------------------
101+
77102
vtkplotlib.PolyData
78103
-------------------
79104

80105
.. autoclass:: vtkplotlib.plots.polydata.PolyData
81106

82107

108+
-----------------
109+
110+
vtkplotlib.legend
111+
-----------------
112+
113+
.. autoclass:: vtkplotlib.plots.Legend.Legend

docs/source/quickstart.rst

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,11 @@ Introduction
1313

1414

1515
A simple library to make 3D graphics using easy. Built on top of VTK. Whilst
16-
VTK is a very versatile library, it still only has a rather low level API. Even the
17-
simplest examples require the construction and linking of a large number of
18-
complicated internal components. This and other factors make writing in it slow
19-
and painful. This library seeks to overcome that by wrapping the all ugliness
20-
into numpy friendly functions to create a 3D equivalent of matplotlib. All the
21-
VTK components/functionality are still accessible but by default are already
22-
setup for you.
16+
VTK is a very versatile library, the learning curve is steep and writing in it
17+
is slow and painful. This library seeks to overcome that by wrapping the all
18+
ugliness into numpy friendly functions to create a 3D equivalent of matplotlib.
19+
All the VTK components/functionality are still accessible but by default are
20+
already setup for you.
2321

2422
Key features
2523
------------
@@ -40,8 +38,10 @@ Requirements for installing:
4038
- `vtk`_
4139
- `future`_
4240

43-
There is no VTK version for Windows users with python 2.7 on PyPi. But you can
44-
get a .whl from `here <https://www.lfd.uci.edu/~gohlke/pythonlibs/#vtk>`_.
41+
It can take VTK a few weeks to release to PyPi for a new Python version so
42+
using the absolute latest Python is not recomended. There is no VTK version for
43+
Windows users with python 2.7 on PyPi. But you can get a .whl from
44+
`here <https://www.lfd.uci.edu/~gohlke/pythonlibs/#vtk>`_.
4545

4646

4747

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
long_description = fh.read()
1414

1515
setup(name='vtkplotlib',
16-
version='1.1.3',
16+
version='1.2.0',
1717
description='High level 3D graphics and plotting',
1818
long_description=long_description,
1919
long_description_content_type="text/markdown",
@@ -29,7 +29,7 @@
2929
# ('models', ['data/models/*'])],
3030
include_package_data=True,
3131
install_requires=[
32-
"vtk<8.2.0",
32+
"vtk",
3333
"numpy",
3434
"pathlib2",
3535
"matplotlib",

vtkplotlib/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
from .plots.Surface import Surface as surface
5454
from .plots.Text import Text as text
5555
from .plots.Text3D import Text3D as text3d, annotate
56-
from .plots.Legend import Legend
56+
from .plots.Legend import Legend as legend
5757

5858
from .plots import BasePlot
5959
from .plots.polydata import PolyData

vtkplotlib/colors.py

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -285,16 +285,16 @@ def __call__(self, uv):
285285
converted_cmaps = {}
286286
temp = []
287287

288-
def vtk_cmap(cmap):
289-
if isinstance(cmap, str):
288+
def as_vtk_cmap(cmap, cache=True):
289+
if cache and isinstance(cmap, str):
290290
if cmap in converted_cmaps:
291291
return converted_cmaps[cmap]
292292
cmap = cm.get_cmap(cmap)
293293

294294
if isinstance(cmap, vtk.vtkLookupTable):
295295
return cmap
296296

297-
if isinstance(cmap, (colors.ListedColormap, colors.LinearSegmentedColormap)):
297+
if cache and isinstance(cmap, (colors.ListedColormap, colors.LinearSegmentedColormap)):
298298
name = cmap.name
299299
if name in converted_cmaps:
300300
return converted_cmaps[name]
@@ -316,44 +316,44 @@ def vtk_cmap(cmap):
316316
table.SetTable(numpy_to_vtk(cmap))
317317

318318
temp.append(cmap)
319-
# if name is not None:
320-
# converted_cmaps[name] = table
319+
if name is not None:
320+
converted_cmaps[name] = table
321321
return table
322322

323323
else:
324-
raise ValueError()
324+
raise ValueError("`cmap` should have shape (n, 3) or (n, 4). Received {}.".format(cmap.shape))
325325

326326

327327

328328

329329

330330

331-
if __name__ == "__main__":
332-
import vtkplotlib as vpl
333-
for args in [((.3, .4, .6), .2),
334-
([5, 8, 10], None),
335-
("red", ),
336-
("orange red", .5),
337-
("Orange_Red", ),
338-
("or33ange_rEd", ),
339-
]:
340-
print("process_color", args, "->", process_color(*args), "\n")
341-
342-
path = Path('C:/Users/Brénainn/Downloads/3dm/duck/Bird_v1_L2.123ca5dbb1bc-8ef6-44e4-b558-3e6e2bbc7dd7/12248_Bird_v1_diff.jpg')
343-
344-
self = TextureMap(path)
345-
self.interpolate = True
346-
347-
n = 1000
348-
t = np.linspace(0, 1, n)
349-
uv = vpl.nuts_and_bolts.zip_axes(*np.meshgrid(t, t))
350-
351-
# plt.figure(figsize=(n // 72,) * 2)
352-
# plt.imshow(self(uv))
353-
# plt.show()
354-
355-
from PIL import Image
356-
im = Image.fromarray((self(uv) * 255).astype(np.uint8))
331+
#if __name__ == "__main__":
332+
# import vtkplotlib as vpl
333+
# for args in [((.3, .4, .6), .2),
334+
# ([5, 8, 10], None),
335+
# ("red", ),
336+
# ("orange red", .5),
337+
# ("Orange_Red", ),
338+
# ("or33ange_rEd", ),
339+
# ]:
340+
# print("process_color", args, "->", process_color(*args), "\n")
341+
#
342+
# path = Path('C:/Users/Brénainn/Downloads/3dm/duck/Bird_v1_L2.123ca5dbb1bc-8ef6-44e4-b558-3e6e2bbc7dd7/12248_Bird_v1_diff.jpg')
343+
#
344+
# self = TextureMap(path)
345+
# self.interpolate = True
346+
#
347+
# n = 1000
348+
# t = np.linspace(0, 1, n)
349+
# uv = vpl.nuts_and_bolts.zip_axes(*np.meshgrid(t, t))
350+
#
351+
## plt.figure(figsize=(n // 72,) * 2)
352+
## plt.imshow(self(uv))
353+
## plt.show()
354+
#
355+
# from PIL import Image
356+
# im = Image.fromarray((self(uv) * 255).astype(np.uint8))
357357
# im.show()
358358

359359
# cmap = plt.get_cmap("Blues")

0 commit comments

Comments
 (0)