Skip to content

Commit

Permalink
adding plotitems
Browse files Browse the repository at this point in the history
  • Loading branch information
dhrogers committed Oct 2, 2023
1 parent 6786f47 commit 1df8587
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 23 deletions.
27 changes: 27 additions & 0 deletions pycinema/filters/PlotItems.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from pycinema import Filter

import PIL
import numpy

class PlotItems(Filter):

def __init__(self):
super().__init__(
inputs={
'x' : 'none',
'y' : 'none',
'line' : 'default',
'color' : 'default',
'width' : 1.0
},
outputs={
'items' : 'none'
}
)

def _update(self):
outs = [[[ self.inputs.x.get(), self.inputs.y.get()],
self.inputs.line.get(), self.inputs.color.get(), self.inputs.width.get()]]
self.outputs.items.set(outs)

return 1
2 changes: 2 additions & 0 deletions pycinema/filters/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from .ImageFilterPIL import *
from .ImageReader import *
from .MaskCompositing import *
from .PlotItems import *
from .ShaderDemoScene import *
from .ShaderFXAA import *
from .ShaderIBS import *
Expand All @@ -21,4 +22,5 @@
from .ShaderSSAO import *
from .ShaderLineAO import *
from .ShaderPointAO import *
from .TextFileReader import *
from .TableWriter import *
62 changes: 39 additions & 23 deletions pycinema/theater/views/PlotView.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@
import pyqtgraph as pg

class PlotView(Filter, FilterView):
PenStyles = {
'dash' : QtCore.Qt.DashLine,
'dashdot' : QtCore.Qt.DashDotLine,
'dashdotdot': QtCore.Qt.DashDotDotLine,
'default' : QtCore.Qt.SolidLine,
'dot' : QtCore.Qt.DotLine,
'solid' : QtCore.Qt.SolidLine
}

def __init__(self):
FilterView.__init__(
Expand All @@ -20,11 +28,10 @@ def __init__(self):
Filter.__init__(
self,
inputs={
'title' : 'Plot Title',
'background' : 'white',
'x_values' : 'none',
'y_values' : 'none',
'table' : []
'title' : 'Plot Title',
'background': 'white',
'plotitems' : 'none',
'table' : []
}
)

Expand All @@ -44,23 +51,32 @@ def _update(self):
# clear on update
self.plot.clear()

# get the ids of the value names
xID = self.getColumnIndex(self.inputs.x_values.get())
yID = self.getColumnIndex(self.inputs.y_values.get())

# convert the table data and get the two arrays
data = self.inputs.table.get()
t = np.array(data)
column = t[:, xID]
xdata = column[1:].astype(float)
row = t[:, yID]
ydata = row[1:].astype(float)

# set up the plot
self.plot.setBackground(self.inputs.background.get())
self.plot.setTitle(self.inputs.title.get())
self.plot.setLabel("left", self.inputs.y_values.get())
self.plot.setLabel("bottom", self.inputs.x_values.get())
self.plot.plot(xdata, ydata)
# get plot items
items = self.inputs.plotitems.get()
for i in items:
axes = i[0]

# get the ids of the value names
xID = self.getColumnIndex(axes[0])
yID = self.getColumnIndex(axes[1])

# convert the table data and get the two arrays
data = self.inputs.table.get()
t = np.array(data)
column = t[:, xID]
xdata = column[1:].astype(float)
row = t[:, yID]
ydata = row[1:].astype(float)

# pen
newpen = pg.mkPen(color = i[2], style=self.PenStyles[i[1]],width=i[3])
newpen.setStyle(self.PenStyles[i[1]])

# set up the plot
self.plot.setBackground(self.inputs.background.get())
self.plot.setTitle(self.inputs.title.get())
self.plot.setLabel("left", axes[0])
self.plot.setLabel("bottom", axes[1])
self.plot.plot(xdata, ydata, pen = newpen)

return 1

0 comments on commit 1df8587

Please sign in to comment.