Skip to content

Commit

Permalink
setup fixing
Browse files Browse the repository at this point in the history
  • Loading branch information
marcomusy committed Oct 12, 2020
1 parent 1447aab commit 8ffdbe6
Show file tree
Hide file tree
Showing 9 changed files with 201 additions and 15 deletions.
31 changes: 31 additions & 0 deletions examples/pyplot/whiskers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
"""Whisker plot with quantiles indication
(horizontal line shows the mean value)"""
from vedo.pyplot import whisker
from vedo import show, buildAxes
import numpy as np

# create 5 whisker bars with some random data
ws = []
for i in range(5):
xval = i*2
data = np.random.randn(25) + i/2
w = whisker(data, bc=i, s=0.5).x(xval)
ws.append(w)

# build custom axes
ax = buildAxes(xrange=[-1,9],
yrange=[-3,5],
htitle='\beta_c -expression: change in time',
xtitle=' ',
ytitle='Level of \beta_c protein in \muM/l',
xValuesAndLabels=[(0,'experiment^A\nat t=1h'),
(4,'experiment^B\nat t=2h'),
(8,'experiment^C\nat t=4h'),
],
xLabelSize=0.02,
)

show(ws, ax, __doc__)
# print('whisker0:', ws[0].info)


34 changes: 32 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,38 @@
setup(
name="vedo",
version=verstr,
packages=["vedo", "vedo.examples"],
scripts=["bin/vedo", "bin/vedo-convert"],
packages=[
"vedo",
"vedo.examples",
"vedo.examples.basic",
"vedo.examples.advanced",
"vedo.examples.pyplot",
"vedo.examples.simulations",
"vedo.examples.tetmesh",
"vedo.examples.volumetric",
"vedo.examples.other.dolfin",
"vedo.examples.other.trimesh",
],
package_dir={
'vedo': 'vedo',
'vedo.examples': 'examples',
'vedo.examples.basic': 'examples/basic',
'vedo.examples.advanced': 'examples/advanced',
'vedo.examples.pyplot': 'examples/pyplot',
'vedo.examples.simulations': 'examples/simulations',
'vedo.examples.tetmesh': 'examples/tetmesh',
'vedo.examples.volumetric': 'examples/volumetric',
'vedo.examples.other.dolfin': 'examples/other/dolfin',
'vedo.examples.other.trimesh': 'examples/other/trimesh',
},
scripts=["bin/vedo",
"bin/vedo-convert",
],
#entry_points={
# 'console_scripts': [
# "vedo = bin/vedo:main"
# ]
#},
install_requires=["vtk<9.0.0", "numpy"],
description="A python module for scientific analysis and visualization of 3D objects and point clouds based on VTK.",
long_description="A python module for scientific visualization, analysis of 3D objects and point clouds based on VTK. Check out https://vedo.embl.es for documentation.",
Expand Down
41 changes: 39 additions & 2 deletions vedo/addons.py
Original file line number Diff line number Diff line change
Expand Up @@ -1189,6 +1189,15 @@ def buildAxes(obj=None,
axesLineWidth=1,
gridLineWidth=1,
reorientShortTitle=True,
htitle="",
hTitleSize=0.03,
hTitleFont=None,
hTitleItalic=True,
hTitleColor=None,
hTitleJustify='bottom-center',
hTitleHorizontalOffset=0,
hTitleVerticalOffset=0.01,
hTitleZOffset=0,
titleDepth=0,
titleFont="", # grab settings.defaultFont
textScale=1.0,
Expand Down Expand Up @@ -1252,6 +1261,15 @@ def buildAxes(obj=None,
- `titleFont`, [''], font for axes titles
- `labelFont`, [''], font for numeric labels
- `textScale`, [1.0], global scaling factor for text elements (titles, labels)
- `htitle`, [''], header title
- `hTitleSize`, [0.03], header title size
- `hTitleFont`, [None], header font (defaults to `titleFont`)
- `hTitleItalic`, [True], header font is italic
- `hTitleColor`, [None], header title color (defaults to `xTitleColor`)
- `hTitleJustify`, ['bottom-center'], origin of the title justification
- `hTitleHorizontalOffset`, [0], control vertical positioning of header title
- `hTitleVerticalOffset`, [0.01], control horizontal positioning of header title
- `hTitleZOffset`, [0], control positioning of header title along z-axis
- `xTitlePosition`, [0.32], title fractional positions along axis
- `xTitleOffset`, [0.05], title fractional offset distance from axis line
- `xTitleJustify`, ["top-right"], title justification
Expand Down Expand Up @@ -1319,7 +1337,9 @@ def buildAxes(obj=None,
else:
vbb = np.zeros(6)
ss = np.zeros(3)
if xrange is None or yrange is None or zrange is None:
if zrange is None:
zrange=(0,0)
if xrange is None or yrange is None:
printc("ERROR in buildAxes(): no mesh given, so must specify ranges.", c='r')
raise RuntimeError()

Expand Down Expand Up @@ -1817,7 +1837,24 @@ def buildAxes(obj=None,
zt.UseBoundsOff()
zt.name = "ztitle "+str(ztitle)
titles.append(zt)
###################################################

################################################### header title
if htitle:
if hTitleFont is None:
hTitleFont = titleFont
if hTitleColor is None:
hTitleColor = xTitleColor
htit = shapes.Text(htitle, s=hTitleSize, font=hTitleFont,
c=hTitleColor, justify=hTitleJustify, depth=titleDepth,
italic=hTitleItalic,
)
wpos = [0.5+hTitleHorizontalOffset, 1+hTitleVerticalOffset, hTitleZOffset]
htit.SetScale(x_aspect_ratios)
htit.pos(wpos)
# htit.UseBoundsOff()
htit.name = "htitle "+str(htitle)
titles.append(htit)


acts = titles + lines + labels + grids + grids2 + highlights
acts += framelines + majorticks + minorticks + cones
Expand Down
11 changes: 10 additions & 1 deletion vedo/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
+ vedo.docs._defs
)

__all__ = ['Base3DProp',
__all__ = [
'Base3DProp',
'BaseActor',
'BaseGrid',
"probePoints",
Expand Down Expand Up @@ -840,6 +841,14 @@ def selectCellArray(self, name):
self._mapper.SetScalarModeToUseCellData()
return self

def removePointArray(self, name):
"""Reomve point array from object."""
self.inputdata().GetPointData().RemoveArray(name)

def removeCellArray(self, name):
"""Reomve cell array from object."""
self.inputdata().GetCellData().RemoveArray(name)

def addPointArray(self, input_array, name):
"""
Add point array and assign it a name.
Expand Down
19 changes: 19 additions & 0 deletions vedo/docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1340,5 +1340,24 @@ def tips():
# :width: 350 px
# :target: flag_labels.py_
# :alt: flag_labels.py

# .. |whiskers.py| replace:: whiskers.py
# .. _whiskers.py: https://github.com/marcomusy/vedo/tree/master/examples/pyplot/.whiskerspy
# .. |whiskers| image:: https://user-images.githubusercontent.com/32848391/95772479-170cd000-0cbd-11eb-98c4-20c5ca342cb8.png
# :width: 350 px
# :target: whiskers.py_
# :alt: whiskers.py

# """

######################################################################## template
# .. |.py| replace:: .py
# .. _.py: https://github.com/marcomusy/vedo/tree/master/examples/pyplot/.py
# .. || image::
# :width: 350 px
# :target: .py_
# :alt: .py
########################################################################



1 change: 0 additions & 1 deletion vedo/examples

This file was deleted.

10 changes: 5 additions & 5 deletions vedo/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -1580,7 +1580,7 @@ def screenshot(filename="screenshot.png", scale=None, returnNumpy=False):
"""
if not settings.plotter_instance or not settings.plotter_instance.window:
colors.printc('\bomb screenshot(): Rendering window is not present, skip.', c='r')
return
return settings.plotter_instance

if filename.endswith('.pdf'):
writer = vtk.vtkGL2PSExporter()
Expand All @@ -1591,7 +1591,7 @@ def screenshot(filename="screenshot.png", scale=None, returnNumpy=False):
writer.SetFileFormatToPDF()
writer.SetFilePrefix(filename.replace('.pdf',''))
writer.Write()
return filename ##########
return settings.plotter_instance ##########
elif filename.endswith('.svg'):
writer = vtk.vtkGL2PSExporter()
writer.SetRenderWindow(settings.plotter_instance.window)
Expand All @@ -1601,7 +1601,7 @@ def screenshot(filename="screenshot.png", scale=None, returnNumpy=False):
writer.SetFileFormatToSVG()
writer.SetFilePrefix(filename.replace('.svg',''))
writer.Write()
return filename ##########
return settings.plotter_instance ##########
elif filename.endswith('.eps'):
writer = vtk.vtkGL2PSExporter()
writer.SetRenderWindow(settings.plotter_instance.window)
Expand All @@ -1611,7 +1611,7 @@ def screenshot(filename="screenshot.png", scale=None, returnNumpy=False):
writer.SetFileFormatToEPS()
writer.SetFilePrefix(filename.replace('.eps',''))
writer.Write()
return filename ##########
return settings.plotter_instance ##########

if scale is None:
scale = settings.screeshotScale
Expand Down Expand Up @@ -1654,7 +1654,7 @@ def screenshot(filename="screenshot.png", scale=None, returnNumpy=False):
writer.SetFileName(filename+'.png')
writer.SetInputData(w2if.GetOutput())
writer.Write()
return filename
return settings.plotter_instance


class Video:
Expand Down
12 changes: 8 additions & 4 deletions vedo/plotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -2024,10 +2024,14 @@ def close(self):
# settings.collectable_actors = []
settings.plotter_instance = None

def screenshot(self, filename='screenshot.png'):
"""Take a screenshot of the Plotter window."""
vedo.io.screenshot(filename)
return self
def screenshot(self, filename='screenshot.png', scale=None, returnNumpy=False):
"""Take a screenshot of the Plotter window.
:param int scale: set image magnification
:param bool returnNumpy: return a numpy array of the image
"""
retval = vedo.io.screenshot(filename, scale, returnNumpy)
return retval

def export(self, filename='scene.npz'):
"""Export scene to file to HTML, X3D or Numpy file."""
Expand Down
57 changes: 57 additions & 0 deletions vedo/pyplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -2068,6 +2068,63 @@ def violin(
return asse


def whisker(data,
s=0.25,
c='k',
lw=2,
bc='blue',
alpha=0.25,
r=3,
jitter=True,
horizontal=False,
):
"""
Generate a "whisker" bar from a 1-dimensional dataset.
:param float s: size of the box
:param c: color of the lines
:param float lw: line width
:param bc: color of the box
:param float alpha: transparency of the box
:param float r: point radius in pixels (use value 0 to disable)
:param bool jitter: add some randomness to points to avoid overlap
:param bool horizontal: set horizontal layout
|whiskers| |whiskers.py|_
"""
xvals = np.zeros_like(data)
if jitter:
xjit = np.random.randn(len(xvals))*s/9
xjit = np.clip(xjit, -s/2.1, s/2.1)
xvals += xjit

dmean = np.mean(data)
dq05 = np.quantile(data, 0.05)
dq25 = np.quantile(data, 0.25)
dq75 = np.quantile(data, 0.75)
dq95 = np.quantile(data, 0.95)

pts = None
if r: pts = shapes.Points([xvals, data], c=c, r=r)

rec = shapes.Rectangle([-s/2, dq25],[s/2, dq75], c=bc, alpha=alpha)
rl = shapes.Line([[-s/2, dq25],[s/2, dq25],[s/2, dq75],[-s/2, dq75]], closed=True)
l1 = shapes.Line([0,dq05,0], [0,dq25,0], c=c, lw=lw)
l2 = shapes.Line([0,dq75,0], [0,dq95,0], c=c, lw=lw)
lm = shapes.Line([-s/2, dmean], [s/2, dmean])
lns = merge(l1,l2,lm,rl)
asse = Assembly([lns, rec, pts])
if horizontal:
asse.rotateZ(-90)
asse.name = "Whisker"
asse.info['mean'] = dmean
asse.info['quantile_05'] = dq05
asse.info['quantile_25'] = dq25
asse.info['quantile_75'] = dq75
asse.info['quantile_95'] = dq95
return asse


def streamplot(X, Y, U, V, direction="both",
maxPropagation=None, mode=1, lw=0.001, c=None, probes=()):
"""
Expand Down

0 comments on commit 8ffdbe6

Please sign in to comment.