Skip to content

Commit ea4fcd9

Browse files
committed
Everything setted up for start with the interactive functions
1 parent e146596 commit ea4fcd9

File tree

2 files changed

+63
-31
lines changed

2 files changed

+63
-31
lines changed

Plotting.py

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,10 @@
44

55
"""
66
TODO:
7-
- I should add the option of default colors and alpha but i couldn't, it's something to fix
7+
-
88
"""
99
class PlotWidget(QtWidgets.QWidget):
10-
"""
11-
12-
Widget for PyQt5 with the plot
10+
"""Widget for PyQt5 with the plot
1311
1412
...
1513
@@ -36,13 +34,29 @@ class PlotWidget(QtWidgets.QWidget):
3634
3735
canvas: matplotlib.backends.backend_qt5agg.FigureCanvasQTAgg
3836
"""
39-
def __init__(self, x: list, y: list, z: list, colors: tuple, alpha: float):
37+
def __init__(self):
4038
super().__init__()
41-
self.fig = Figure()
42-
self.canvas = FigureCanvas(self.fig)
43-
self.axes = self.fig.add_subplot(111,projection='3d')
39+
self.fig = Figure() # Create a matplotlib figure
40+
self.canvas = FigureCanvas(self.fig) # Get the plot image
41+
self.axes = self.fig.add_subplot(111,projection='3d') # Create matpotlib axes
4442

45-
layout = QtWidgets.QVBoxLayout(self)
43+
layout = QtWidgets.QVBoxLayout(self)
4644
layout.addWidget(self.canvas)
4745

48-
self.axes.scatter(x, y, z, c = colors, alpha = alpha)
46+
def scatter(self,xyzgrid:list,colors:list):
47+
"""Scatter the data
48+
49+
...
50+
51+
Parameters
52+
----------
53+
xyzgrid:list
54+
data for plotting
55+
xyzgrid[0] the x data
56+
xyzgrid[1] the y data
57+
xyzgrid[2] the z
58+
colors:list
59+
colors
60+
"""
61+
self.axes.clear()
62+
self.axes.scatter(xyzgrid[0],xyzgrid[1],xyzgrid[2],c = colors,alpha=0.7)

main.py

Lines changed: 39 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,6 @@
1212

1313
from Plotting import PlotWidget #The plot object
1414

15-
"""Transformation matrix"""
16-
transformationMatrix = Matrix([[1, 0, 0],
17-
[0, 0.5, 0],
18-
[0, 0, 1]])
19-
2015
def transformPoint(x,y,z):
2116
"""Return the vector transformed
2217
@@ -51,28 +46,51 @@ def get_grid(min,max):
5146
xyzgrid = column_stack([[x, y,z] for x in xvals for y in yvals for z in zvals])
5247
return xyzgrid
5348

54-
if __name__ == "__main__":
49+
def get_transformedGrid(originalGrid, transformationMatrix):
50+
"""Return a grid in x, y and z transformed
51+
52+
...
5553
56-
originalGrid = get_grid(-2,2)
54+
Parameters
55+
----------
56+
originalGrid
57+
58+
transformationMatrix
59+
60+
"""
5761
transformedGrid = transformPoint(originalGrid[0],originalGrid[1],originalGrid[2])
58-
xyzgrid = array([transformedGrid[0,:][0,:], #
59-
transformedGrid[1,:][0,:], # Save the transformed grid as a numpy array
60-
transformedGrid[2,:][0,:]]) #
62+
return array([transformedGrid[0,:][0,:], #
63+
transformedGrid[1,:][0,:], # Save the transformed grid as a numpy array
64+
transformedGrid[2,:][0,:]]) #
65+
66+
def adjust_plot(axes):
67+
axes.set_xlim([-2, 2]) #
68+
axes.set_ylim([-2, 2]) # Set the limits of the plot
69+
axes.set_zlim([-2, 2]) #
70+
axes.axis('on') # Show the axis
71+
axes.set_xlabel('x') #
72+
axes.set_ylabel('y') # Axes names
73+
axes.set_zlabel('z') #
74+
axes.grid(False) # Don't show the grid
75+
axes.view_init(10,5) # View init at 15 and 5 degrees
76+
77+
if __name__ == "__main__":
78+
"""Transformation matrix"""
79+
transformationMatrix = Matrix([[1, 0, 0],
80+
[0, 1, 0],
81+
[0, 1, 1]])
82+
83+
originalGrid = get_grid(-2,2) # Create a straigh grid
84+
xyzgrid = get_transformedGrid(originalGrid, transformationMatrix) # get a transformed grid
6185

6286
colors = list(map(colorizer, originalGrid[0], originalGrid[1], originalGrid[2])) # Asign the colors to the points
6387

6488
app = QtWidgets.QApplication([])
65-
plot = PlotWidget(xyzgrid[0], xyzgrid[1], xyzgrid[2], colors = colors, alpha = 0.7)
66-
67-
plot.axes.set_xlim([-2, 2]) #
68-
plot.axes.set_ylim([-2, 2]) # Set the limits of the plot
69-
plot.axes.set_zlim([-2, 2]) #
70-
plot.axes.axis('on') # Show the axis
71-
plot.axes.set_xlabel('x') #
72-
plot.axes.set_ylabel('y') # Axes names
73-
plot.axes.set_zlabel('z') #
74-
plot.axes.grid(False) # Don't show the grid
75-
plot.axes.view_init(10,5) # View init at 15 and 5 degrees
89+
plot = PlotWidget()
90+
91+
plot.scatter(xyzgrid,colors)
92+
93+
adjust_plot(plot.axes)
7694

7795
plot.show()
7896
app.exec()

0 commit comments

Comments
 (0)