22from math import pi , sin , cos , acos , atan2 , degrees , radians , sqrt
33import re
44
5- from PyQt5 import QtWidgets
5+ from PyQt5 import QtWidgets , QtCore
66from matplotlib .pyplot import colorbar , imread , get_cmap
77from matplotlib .figure import Figure
88from matplotlib .backends .backend_qt5agg import (
1616 PolyCollection ,
1717 LineCollection ,
1818)
19- from matplotlib .mlab import griddata
19+ # from matplotlib.mlab import griddata
2020import matplotlib .patheffects as PathEffects
2121from matplotlib .font_manager import FontProperties
2222from mpl_toolkits .axes_grid .axislines import Subplot
@@ -148,6 +148,7 @@ def __init__(self, settings, projection, parent=None):
148148 self .circle_elements = []
149149 self .drag_rotate_mode = False
150150 self .current_rotation = np .eye (3 )
151+ self .scroll_rotation = 0.0
151152 self .last_rotation = np .eye (3 )
152153 self .last_rotation_I = np .eye (3 )
153154
@@ -162,6 +163,9 @@ def connect_measure(self):
162163 self .cidmotion = self .plotFigure .canvas .mpl_connect (
163164 "motion_notify_event" , self .measure_motion
164165 )
166+ self .cidmotion = self .plotFigure .canvas .mpl_connect (
167+ "scroll_event" , self .measure_motion
168+ )
165169 # http://stackoverflow.com/a/18145817/1457481
166170
167171 def measure_press (self , event ):
@@ -208,6 +212,7 @@ def measure_release(self, event):
208212 self .last_rotation = self .current_rotation
209213 self .last_rotation_I = np .linalg .inv (self .current_rotation )
210214 self .current_rotation = np .eye (3 )
215+ self .scroll_rotation = 0.0
211216 self .plot_canvas .draw ()
212217
213218 # thanks forever to http://stackoverflow.com/a/8956211/1457481 for basics on blit
@@ -272,9 +277,25 @@ def measure_motion(self, event):
272277 c_sphere = sphere (* c )
273278
274279 if self .drag_rotate_mode :
280+ if event .name == "scroll_event" :
281+ # https://stackoverflow.com/q/49316067/1457481
282+ self .scroll_rotation += (
283+ 5 * event .step
284+ if QtWidgets .QApplication .keyboardModifiers ()
285+ == QtCore .Qt .ControlModifier
286+ else event .step
287+ )
275288 rotation_matrix = self .last_rotation .dot (
276289 au_c .get_rotation_matrix (- theta )
277- )
290+ ) if self .button_pressed == 1 else self .last_rotation
291+ if self .button_pressed == 1 :
292+ rotation_matrix = rotation_matrix .dot (
293+ b .get_rotation_matrix (radians (self .scroll_rotation ))
294+ )
295+ else :
296+ rotation_matrix = rotation_matrix .dot (
297+ a .get_rotation_matrix (radians (self .scroll_rotation ))
298+ )
278299 self .current_rotation = rotation_matrix
279300 for point , element in self .point_elements :
280301 Xp , Yp = self .project (* (point .dot (rotation_matrix )).T )
@@ -522,8 +543,7 @@ def plot_arrow(self, planes, lines, arrow_settings, has_sense, sliplinear):
522543 if plane [- 1 ] > 0 :
523544 plane = - plane
524545 arrow_from = (
525- cos (arrowsize / 2.0 ) * plane
526- + sin (arrowsize / 2.0 ) * line
546+ cos (arrowsize / 2.0 ) * plane + sin (arrowsize / 2.0 ) * line
527547 )
528548 arrow_to = (
529549 cos (- arrowsize / 2.0 ) * plane
@@ -536,8 +556,8 @@ def plot_arrow(self, planes, lines, arrow_settings, has_sense, sliplinear):
536556 invert_positive = False
537557 )
538558 else :
539- line_direction = line [:2 ]/ np .linalg .norm (line [:2 ])
540- dx , dy = line_direction * arrow_settings ["arrowsize" ]* 0.0075
559+ line_direction = line [:2 ] / np .linalg .norm (line [:2 ])
560+ dx , dy = line_direction * arrow_settings ["arrowsize" ] * 0.0075
541561 x , y = self .project (* line , invert_positive = True )
542562 X , Y = [x - dx , x + dx ], [y - dy , y + dy ]
543563 if not sense :
@@ -654,15 +674,16 @@ def plot_contours(
654674 b"[^-\\ d\\ .]+" , contour_settings ["intervals" ]
655675 )
656676 ]
657- xi = yi = np .linspace (- 1.1 , 1.1 , contour_settings ["cresolution" ])
658- X , Y = self .project (* nodes .T , ztol = 0.1 )
677+ # xi = yi = np.linspace(-1.1, 1.1, contour_settings["cresolution"])
678+ # X, Y = self.project(*nodes.T, ztol=0.1)
679+ X , Y = self .project (* nodes .T , invert_positive = False )
659680
660- zi = griddata (X , Y , count , xi , yi , interp = "linear" )
681+ # zi = griddata(X, Y, count, xi, yi, interp="linear")
661682 if contour_check_settings ["fillcontours" ]:
662- contour_plot = axes .contourf (
663- xi ,
664- yi ,
665- zi ,
683+ contour_plot = axes .tricontourf (
684+ X ,
685+ Y ,
686+ count ,
666687 intervals ,
667688 cmap = contour_settings ["cmap" ],
668689 linestyles = contour_settings ["linestyles" ],
@@ -684,20 +705,20 @@ def plot_contours(
684705 or not contour_check_settings ["fillcontours" ]
685706 ):
686707 if contour_check_settings ["solidline" ]:
687- contour_lines_plot = axes .contour (
688- xi ,
689- yi ,
690- zi ,
708+ contour_lines_plot = axes .tricontour (
709+ X ,
710+ Y ,
711+ count ,
691712 intervals ,
692713 colors = contour_line_settings ["colors" ],
693714 linestyles = contour_settings ["linestyles" ],
694715 linewidths = contour_line_settings ["linewidths" ],
695716 )
696717 else :
697- contour_lines_plot = axes .contour (
698- xi ,
699- yi ,
700- zi ,
718+ contour_lines_plot = axes .tricontour (
719+ X ,
720+ Y ,
721+ count ,
701722 intervals ,
702723 cmap = contour_line_settings ["cmap" ],
703724 linestyles = contour_settings ["linestyles" ],
0 commit comments