Skip to content

Commit

Permalink
4.5
Browse files Browse the repository at this point in the history
  • Loading branch information
marcomusy committed Sep 17, 2019
1 parent 30f5899 commit 4547246
Show file tree
Hide file tree
Showing 39 changed files with 1,164 additions and 341 deletions.
4 changes: 2 additions & 2 deletions bin/vtkplotter
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ def draw_scene():
vp.window.AddObserver("AbortCheckEvent", CheckAbort)

# add histogram of scalar
from vtkplotter import histogram
from vtkplotter.analysis import histogram2D

dims = img.GetDimensions()
nvx = min(100000, dims[0] * dims[1] * dims[2])
Expand All @@ -292,7 +292,7 @@ def draw_scene():
d = img.GetScalarComponentAsFloat(ix, iy, iz, 0)
data.append(d)

plot = histogram(
plot = histogram2D(
data, bins=40, logscale=1, c="gray", bg="gray", pos=(0.78, 0.065)
)
plot.GetPosition2Coordinate().SetValue(0.197, 0.20, 0)
Expand Down
2 changes: 1 addition & 1 deletion examples/advanced/fitplanes.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
vp += Arrow(cn, cn + v / 15.0, c="g")
variances.append(plane.info["variance"])

vp += histogram(variances, title="variance", c="g")
vp += histogram(variances, c="g").scale([30,.03,30]).pos(-0.5, -1.2, -.6)

vp += Text(__doc__, pos=1)
vp.show(viewup="z")
8 changes: 0 additions & 8 deletions examples/advanced/fitspheres1.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
For some of these point we show the fitting sphere.
Red lines join the center of the sphere to the surface point.
Blue points are the N points used for fitting.
Green histogram is the distribution of residuals from the fitting.
Red histogram is the distribution of the curvatures (1/r**2).
Fitted radius can be accessed from actor.info['radius'].
"""
from __future__ import division, print_function
Expand All @@ -16,7 +14,6 @@
# load mesh and increase by a lot (N=2) the nr of surface vertices
s = vp.load(datadir+"cow.vtk").alpha(0.3).subdivide(N=2)

reds, invr = [], []
for i, p in enumerate(s.getPoints()):
if i % 1000:
continue # skip most points
Expand All @@ -27,11 +24,6 @@
vp += sph
vp += Points(pts)
vp += Line(sph.info["center"], p, lw=2)
reds.append(sph.info["residue"])
invr.append(1 / sph.info["radius"] ** 2)

vp += histogram(reds, title="residue", bins=12, c="g", pos=3)
vp += histogram(invr, title="1/r**2", bins=12, c="r", pos=4)

vp += Text(__doc__)
vp.show(viewup="z")
2 changes: 1 addition & 1 deletion examples/basic/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ python example.py
| | |
| [![fxy](https://user-images.githubusercontent.com/32848391/50738863-bfccf800-11d8-11e9-882d-7b217aceb55a.jpg)](https://github.com/marcomusy/vtkplotter/blob/master/examples/basic/fxy.py)<br/> `fxy.py` | Draw a surface representing a function _f(x, y)_ defined as a string/formula or as a reference to an external already existing function. <br/>Red points indicate where the function does not exist. |
| | |
| [![histo2d](https://user-images.githubusercontent.com/32848391/50738861-bfccf800-11d8-11e9-9698-c0b9dccdba4d.jpg)](https://github.com/marcomusy/vtkplotter/blob/master/examples/basic/histo2D.py)<br/> `histo2D.py` | Make a histogram of two variables with hexagonal binning. |
| [![histo2d](https://user-images.githubusercontent.com/32848391/50738861-bfccf800-11d8-11e9-9698-c0b9dccdba4d.jpg)](https://github.com/marcomusy/vtkplotter/blob/master/examples/basic/histo2D.py)<br/> `histoHexagonal.py` | Make a histogram of two variables with hexagonal binning. |
| | |
| [![keypress](https://user-images.githubusercontent.com/32848391/50738860-bfccf800-11d8-11e9-96ca-dab2bb7adae3.jpg)](https://github.com/marcomusy/vtkplotter/blob/master/examples/basic/keypress.py)<br/> `keypress.py` | How to implement a custom function that is triggered by pressing a keyboard button when the rendering window is in interactive mode. <br/>In the example, every time a key is pressed the picked point of the mesh is used to add a sphere and some info is printed. |
| | |
Expand Down
4 changes: 2 additions & 2 deletions examples/basic/align2.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "c36f73641ab1421fab19091a99c5f175",
"model_id": "4177c602a52e48148251a3635bd676ac",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Plot(antialias=3, axes=['x', 'y', 'z'], background_color=16777215, camera=[2.1504162283002834, 4.9575156559299"
"Plot(antialias=3, axes=['x', 'y', 'z'], background_color=16777215, camera=[2.238617303212521, 5.12911044410189"
]
},
"metadata": {},
Expand Down
4 changes: 2 additions & 2 deletions examples/basic/connVtx.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "6afe2573e4ed40789d86033940337f3c",
"model_id": "179089faa27c43a3aee25c8405ceb299",
"version_major": 2,
"version_minor": 0
},
Expand Down Expand Up @@ -61,7 +61,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.3"
"version": "3.6.8"
}
},
"nbformat": 4,
Expand Down
10 changes: 10 additions & 0 deletions examples/basic/donutPlot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from vtkplotter import donutPlot

title = "A donut plot"
fractions = [0.1, 0.2, 0.3, 0.1, 0.3]
colors = [ 1, 2, 3, 4, 'white']
labels = ["stuff1", "stuff2", "compA", "compB", ""]

dn = donutPlot(fractions, c=colors, labels=labels, title=title)

dn.show(axes=None, bg='w')
19 changes: 10 additions & 9 deletions examples/basic/fxy.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,36 @@
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 10,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "1a76cbee3deb4be691a8ef693570473c",
"model_id": "3f3e2d4fa8d146b8ad69c3d498145f2a",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Plot(antialias=3, axes=['x', 'y', 'z'], background_color=16777215, camera=[3.794147738309014, 3.79414773830901"
"Plot(antialias=3, axes=['x', 'y', 'z'], background_color=16777215, camera=[3.760363867861654, 3.76036386786165"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"\"\"\"Example for fxy() method.\n",
"Draw a surface representing the 3D function specified as a string\n",
"or as a reference to an external already existing function.\n",
"Red points indicate where the function does not exist.\"\"\"\n",
"\"\"\"\n",
"Draw a surface representing a 2-var function specified \n",
"as a string or as a reference to an external existing function.\n",
"\"\"\"\n",
"from vtkplotter import Plotter, fxy, sin, cos\n",
"\n",
"def my_z(x, y):\n",
" return sin(2 * x * y) * cos(3 * y) / 2\n",
"\n",
"f1 = fxy(my_z, zlevels=0, showNan=False).c('lightblue')\n",
"f1 = fxy(my_z, zlevels=0).c('lightblue')\n",
"#f1 = fxy(\"sin(2*x*y)*cos(3*y)/2\", zlevels=0).c('lightblue')\n",
"\n",
"f1.show(viewup='z')"
]
Expand Down Expand Up @@ -59,7 +60,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.3"
"version": "3.6.8"
}
},
"nbformat": 4,
Expand Down
12 changes: 4 additions & 8 deletions examples/basic/fxy.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,22 @@
"""
Example for function() method.
Draw a surface representing the 3D function specified as a string
or as a reference to an external already existing function.
Draw a surface representing a 2-var function specified
as a string or as a reference to an external existing function.
Red points indicate where the function does not exist.
"""
print(__doc__)
from vtkplotter import Plotter, fxy, sin, cos, show
from vtkplotter import fxy, sin, cos, show


def my_z(x, y):
return sin(2 * x * y) * cos(3 * y) / 2


# draw at renderer nr.0 the first actor, show it with a texture
# an existing function z(x,y) can be passed:
f1 = fxy(my_z)

# red dots are shown where the function does not exist (y>x):
# if vp is set to verbose, sympy calculates derivatives and prints them:
f2 = fxy("sin(3*x)*log(x-y)/3")

# specify x and y ranges and z vertical limits:
f3 = fxy("log(x**2+y**2 - 1)", x=[-2, 2], y=[-2, 2], zlimits=[-1, 1.5])
f3 = fxy("log(x**2+y**2-1)", x=[-2,2], y=[-1,8], zlimits=[-1,None])

show(f1, f2, f3, N=3, axes=1, sharecam=False, bg="w")
26 changes: 0 additions & 26 deletions examples/basic/histo2D.py

This file was deleted.

25 changes: 25 additions & 0 deletions examples/basic/histoHexagonal.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
"""2D histogram with hexagonal binning."""
from vtkplotter import *
import numpy as np

N = 2000
x = np.random.randn(N) * 1.0
y = np.random.randn(N) * 1.5

# hexagonal histogram
histo = hexHistogram(x, y, bins=10, fill=True, cmap='terrain')

# scatter plot:
pts = Points([x, y, np.zeros(N)+6], c="black", alpha=0.05)

f = r'f(x, y)=A \exp \left(-\left(\frac{\left(x-x_{o}\right)^{2}}'
f+= r'{2 \sigma_{x}^{2}}+\frac{\left(y-y_{o}\right)^{2}}'
f+= r'{2 \sigma_{y}^{2}}\right)\right)'
formula = Latex(f, c='k', s=1.5).rotateZ(90).rotateX(90).pos(1,-1,1)

#settings.useParallelProjection = True
settings.xtitle = "x gaussian, s=1.0"
settings.ytitle = "y gaussian, s=1.5"
settings.ztitle = "dN/dx/dy"

show(histo, pts, formula, Text(__doc__), axes=1, verbose=0, bg="white")
41 changes: 41 additions & 0 deletions examples/basic/histoPolar.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
from vtkplotter import polarHistogram, Hyperboloid, show
import numpy as np
np.random.seed(3)


##################################################################
radhisto = polarHistogram(np.random.rand(200)*6.28,
title="random orientations",
bins=10,
#c='orange', #uniform color
labels=["label"+str(i) for i in range(10)],
)

show(radhisto, at=0, N=2, axes=0, sharecam=False, bg="white")


##################################################################
hyp = Hyperboloid(res=20).cutWithPlane().rotateY(-90)
hyp.color('grey').alpha(0.3)

# select 10 random indeces of points on the surface
idx = np.random.randint(0, hyp.NPoints(), size=10)

radhistos = []
for i in idx:
#generate a random histogram
rh = polarHistogram(np.random.randn(100),
bins=12,
r1=0.2, # inner radius
phigap=1.0, # leave a space btw phi bars
cmap='viridis_r',
showDisc=False,
showAngles=False,
showErrors=False,
)
rh.scale(0.15) # scale histogram to make it small
rh.pos(hyp.getPoint(i)) # set its position on the surface
rh.orientation(hyp.normalAt(i)) # orient it along normal
radhistos.append(rh)

show(hyp, radhistos, at=1, interactive=True)
14 changes: 14 additions & 0 deletions examples/basic/histogram.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from vtkplotter import *
import numpy as np

data1 = np.random.randn(500)*3+10
data2 = np.random.randn(500)*2+ 7

h1 = histogram(data1, fill=True, outline=False, errors=True)
h2 = histogram(data2, fill=False, lc='firebrick', lw=4)
h2.z(0.1) # put h2 in front of h1

h1.scale([1, 0.2, 1]) # set a common y-scaling factor
h2.scale([1, 0.2, 1])

show(h1, h2, bg='white', axes=1)
41 changes: 25 additions & 16 deletions examples/basic/multiwindows.py
Original file line number Diff line number Diff line change
@@ -1,41 +1,50 @@
"""
Example of drawing objects on different windows
and/or subwindows within the same window.
We split the main window in a 25 subwindows and draw something
in specific windows numbers.
We split the main window in many subwindows and draw
somethingon specific windows numbers.
Then open an independent window and draw a shape on it.
"""
print(__doc__)
from vtkplotter import *

from vtkplotter import Plotter, Text, datadir


##########################################################################
# this is one instance of the class Plotter with 5 raws and 5 columns
vp1 = Plotter(shape=(5, 5), axes=0, bg="white")
# having set shape=(n,m), script execution after the show() is not held
vp1 = Plotter(shape=(5,5), axes=0, bg="white")

# set a different background color for a specific subwindow (the last one)
vp1.renderers[24].SetBackground(0.8, 0.9, 0.9) # use vtk method SetBackground()

# load the actors and give them a name
a = vp1.load(datadir+"airboat.vtk").legend("some legend")
a = vp1.load(datadir+"airboat.vtk")
b = vp1.load(datadir+"cessna.vtk", c="red")
c = vp1.load(datadir+"atc.ply")

# show a text in each renderer
for i in range(25):
txt = Text("renderer\nnr."+str(i), c='k', s=0.5, font='arial')
vp1.show(txt, at=i, interactive=0)
txt = Text("renderer\nnr."+str(i), c='k', font='arial', s=1)
vp1.show(txt, at=i)

vp1.show(a, at=22)
vp1.show(a, at= 6)
vp1.show(b, at=23)
vp1.show(c, at=24, interactive=0)
vp1.show(c, at=24)


############################################################
##########################################################################
# declare a second independent instance of the class Plotter
vp2 = Plotter(pos=(500, 250), bg=(0.9, 0.9, 1)) # blue-ish background
# shape can also be given as a string, e.g.:
# shape="2/6" means 2 renderers above and 6 below
# shape="3|1" means 3 renderers on the left and one on the right

s = load(datadir+'pumpkin.vtk')

#settings.multiRenderingSplittingPosition = 0.5

vp2 = Plotter(pos=(500, 250), shape='2/6')

vp2.load(datadir+"porsche.ply").legend("an other window")
for i in range(len(vp2.renderers)):
s2 = s.clone().color(i)
txt = Text('renderer #'+str(i))
vp2.show(s2, txt, at=i)

vp2.show() # show and interact with mouse and keyboard
interactive()
15 changes: 15 additions & 0 deletions examples/basic/polarPlot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from vtkplotter import polarPlot, show
import numpy as np

title = "A (splined) polar plot"
angles = [ 0, 20, 60, 160, 200, 250, 300, 340]
distances = [0.1, 0.2, 0.3, 0.5, 0.6, 0.4, 0.2, 0.1]

dn1 = polarPlot([angles, distances], deg=True, spline=False,
c='green', alpha=0.5, title=title, vmax=0.6)

dn2 = polarPlot([angles, np.array(distances)/2], deg=True,
c='tomato', alpha=1, showDisc=False, vmax=0.6)
dn2.z(0.01) # set z above 0, so that plot is visible

show(dn1, dn2, axes=None, bg='white')
2 changes: 1 addition & 1 deletion examples/notebooks/sphere.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "62ea648105d74f76ac8d8d4bc9f8bb99",
"model_id": "6328d5a8448840f88ee1d5aa771fb292",
"version_major": 2,
"version_minor": 0
},
Expand Down
Loading

0 comments on commit 4547246

Please sign in to comment.