Skip to content

Commit 72d23aa

Browse files
Fixed Installation with setup.py. Updated notebook. Made quiver plot arrows to be drawn from the center by default. Added requirements to README file
1 parent 9e98e5b commit 72d23aa

File tree

6 files changed

+98
-89
lines changed

6 files changed

+98
-89
lines changed

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ Clone the repository and from it, as a root user, do
3232

3333
This will add `plot_vtk_matplotlib` to the Python libraries.
3434

35+
The library needs `matplotlib`, `scipy` and `vtk` to work. It is recommended
36+
to install the latest versions using `pip`.
37+
3538
# License
3639

3740
A BSD license statement can be found in the `license.txt` file.

minimal_example.py

-16
This file was deleted.

plot_vtk_matplotlib/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from plot_vtk_matplotlib import *

plot_vtk_matplotlib/plot_vtk_matplotlib.py

+31-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
"""
22
3-
FUTURE IDEAS::
3+
plot_vtk_matplotlib library for plotting VTK files in two dimensions
4+
using Matplotlib
5+
6+
Authors: David Cortes, Hans Fangohr
7+
8+
License: BSD, stated in the Github repository:
9+
https://github.com/fangohr/plot_vtk_matplotlib
10+
11+
12+
FUTURE IDEAS::
413
514
A 3D plot is also possible to do, but the plt.quiver() function
615
is still under development, and handling thousands of vectors
@@ -22,8 +31,9 @@
2231

2332
import colorsys
2433

25-
matplotlib.rcParams.update({'font.size': 22}) # This should be equivalent
26-
# # in structure than before
34+
# We can change Matplotlib parameters as
35+
matplotlib.rcParams['font.size'] = 22
36+
# Or as
2737
matplotlib.rcParams.update({'xtick.labelsize': 16})
2838
matplotlib.rcParams.update({'ytick.labelsize': 16})
2939

@@ -101,7 +111,10 @@ def extract_data(self):
101111
102112
"""
103113

104-
# Check the type of file to load it according ot it
114+
# Check the type of file to load it according to its grid structure
115+
# which was specified when calling the class These dictionary entries
116+
# return the corresponding VTK Reader functions, so they can be easily
117+
# called according to the class argument
105118
reader_type = {
106119
'XMLUnstructuredGrid': lambda: vtk.vtkXMLUnstructuredGridReader(),
107120
'XMLStructuredGrid': lambda: vtk.vtkXMLStructuredGridReader(),
@@ -240,6 +253,7 @@ def plot_vtk(self,
240253
colorbar_label='',
241254
quiver_type='raw_cmap',
242255
quiver_color='k',
256+
pivot='middle',
243257
nx_q=20,
244258
ny_q=20,
245259
frame=True,
@@ -356,6 +370,10 @@ def plot_vtk(self,
356370
quiver_color :: Arrow color if one of the 'color' options was
357371
specified in the quiver_type argument
358372
373+
pivot :: By default we make the arrows to be drawn at the
374+
center of the grid nodes. This option is from
375+
the matplotlib quiver function
376+
359377
nx_q, ny_q :: Resolution in the x and y directions for the
360378
arrows in the quiver plot if one of the
361379
interpolated quiver_type options are passed
@@ -644,6 +662,7 @@ def convert_to_rgb(a):
644662
# component of m_component
645663
quiv[v_component],
646664
cmap=quiver_map,
665+
pivot=pivot,
647666
**quiver_args
648667
)
649668
elif (quiver_type == 'interpolated_colour'
@@ -653,6 +672,7 @@ def convert_to_rgb(a):
653672
quiv['vx'],
654673
quiv['vy'],
655674
color=quiver_color,
675+
pivot=pivot,
656676
**quiver_args
657677
)
658678
elif not quiver_type:
@@ -689,6 +709,7 @@ def plot_quiver(self,
689709
interpolator='scipy',
690710
quiver_type='raw_cmap',
691711
quiver_color='k',
712+
pivot='middle',
692713
linewidth=0.7,
693714
x_min=-10, y_min=-10,
694715
x_max=10, y_max=10,
@@ -757,6 +778,10 @@ def plot_quiver(self,
757778
quiver_color :: Arrow color if one of the 'color' options was
758779
specified in the quiver_type argument
759780
781+
pivot :: By default we make the arrows to be drawn at the
782+
center of the grid nodes. This option is from
783+
the matplotlib quiver function
784+
760785
linewidth :: Arrows line width
761786
762787
x_min, x_max :: Range of spatial x values to be used in the
@@ -868,6 +893,7 @@ def plot_quiver(self,
868893
linewidth=linewidth,
869894
edgecolor='k',
870895
facecolor=None,
896+
pivot=pivot,
871897
**kwargs
872898
)
873899

@@ -881,6 +907,7 @@ def plot_quiver(self,
881907
alpha=alpha,
882908
linewidth=linewidth,
883909
color=quiver_color,
910+
pivot=pivot,
884911
**kwargs
885912
)
886913

setup.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,8 @@
66
packages=['plot_vtk_matplotlib'],
77
license='BSD',
88
description='Library to plot VTK files in 2D with Matplotlib',
9-
install_requires=['scipy', 'matplotlib'],
9+
# We comment this to avoid upgrading matplotlib when
10+
# instaling the library. Could be used in the future.
11+
# install_requires=['scipy', 'matplotlib'],
12+
author_email='[email protected]'
1013
)

tutorial/plot_vtk_matplotlib_tutorial.ipynb

+59-68
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)