Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plot does not update when zooming in #38

Closed
Spandyie opened this issue Jan 3, 2019 · 6 comments
Closed

Plot does not update when zooming in #38

Spandyie opened this issue Jan 3, 2019 · 6 comments

Comments

@Spandyie
Copy link

Spandyie commented Jan 3, 2019

I have written wxmplot panel which is linked to the selection made by user. The plotting feature works perfectly fine. However when I try to zoom in into the graph, it zooms into the graph created by previous event. In other words the everytime I make new selection the graph is not being updated

@newville
Copy link
Owner

newville commented Jan 3, 2019

@Spandyie Zooming works OK for me. Without example code and more details of what you expect to happen, I cannot tell what is not working as you expect.

@Spandyie
Copy link
Author

Spandyie commented Jan 3, 2019

@newville Below is the Python class which uses wxmpanel, I created a derived panel class using wxmpanel.PlotPanel. Everytime I call new instance of ConvexHullPlot() the zoom-in feature zooms into the graph created by previous instance of wxmplot

class ConvexHullPlot(wxmplot.PlotPanel):
    # TODO: The Convex Hull plot should be visible along with the point, test the outliers
    """" Plots the convex hull plot """
    def __init__(self, parent_panel, bm_torsion=None,bm_torsion_array=None, table_id="1"):
        super().__init__(parent=parent_panel, size=(600, 600))
        #########################################
        tor_bend_object = OpenThreshold(table_id)        # this class creates threshold object
        torsion_array = tor_bend_object.get_torsion()
        bm_array = tor_bend_object.get_bending_moment()
        data_list = [Point(int(x), int(y)) for x, y in zip(torsion_array,bm_array)]
        ###########################################
        # create a stack of convex hull object,
        stack_object = ConvexHull(data_list)        # creates a convexhull class
        # creating a deep-copy of the stack to plot the graph
        stacks = copy.deepcopy(stack_object.hull)
        # check if the stack object is empty or not
        assert not stack_object.hull.isEmpty
        t = []
        s = []
        # check the size of the stack
        length_stack = stacks.size
        assert length_stack >= 3
        for i in range(length_stack):
            temp_point = stacks.pop()
            t.append(temp_point.x)
            s.append(temp_point.y)
        #########################################
        t = np.array(t)
        s = np.array(s)
        #############################################
        # plot outliers in red and non-outliers in green
        if bm_torsion is not None:
            outlier_detector = DetectOutlier(bm_torsion, stack_object.hull)
            if outlier_detector.is_outlier():
                # plot the outlier
                duration = 1000  # millisecond
                freq = 1000 # Hz
                x, y = np.array([bm_torsion.get_x()]), np.array([bm_torsion.get_y()])
                self.scatterplot(x, y, marker='*', s=100, color='red', xlabel="Bending Moment", ylabel="Torsion Moment")
                self.oplot(t, s, alpha=0.6, color="red")
                winsound.Beep(freq, duration)  # play the sound
                self.status_message = "Outlier detected"
            else:
                # plot the inlier
                x, y = np.array([bm_torsion.get_x()]), np.array([bm_torsion.get_y()])
                self.scatterplot(x, y, marker='*', s=100, color='green', xlabel="Bending Moment", ylabel="Torsion Moment")
                self.oplot(t, s,  alpha=0.6, color="red")
                self.status_message = "Data is within threshold"

        elif bm_torsion is None and bm_torsion_array is not None:
            bending_moment_all = list()
            torsion_moment_all = list()
            points_on_the_hull = copy.deepcopy(stack_object.hull)
            for point in bm_torsion_array:
                # create an outlier detector object
                # refill the convex hull because it gets emptied after outlier detection
                # points_on_the_hull = copy.deepcopy(stack_object.hull)
                # outlier_detector = DetectOutlier(point, points_on_the_hull)
                bending_moment_all.append(point.get_x())
                torsion_moment_all.append(point.get_y())
                # check if the point in the array is outlier
                #if outlier_detector.is_outlier():
                #    pass
                #else:
                #    pass
            bending_moment_all = np.array(bending_moment_all)
            torsion_moment_all = np.array(torsion_moment_all)
            self.scatterplot(bending_moment_all, torsion_moment_all, marker="*")
            self.oplot(t, s, color="red")
            self.set_xlabel("Bending Moment")
            self.set_ylabel("Torsion Moment")
        else:
            self.plot(t, s, color="blue")

@newville
Copy link
Owner

newville commented Jan 3, 2019

@Spandyie That code does not run for me. If you are creating instances of this class many times, wouldn't you need to say how you were doing that? Are you reusing a panel or something? I have no idea.

If you suspect there is a problem with wxmplot, please provide a minimal example that demonstrates whatever problem you are seeing.

@Spandyie
Copy link
Author

Spandyie commented Jan 3, 2019

@newville I apologise for leaving out the details. This code has many other dependencies class such as DetectOutlier() , ConvexHull() which is part of a larger software.

The Class ConvexHullPlot()'s parent is another subpanel. Yes I am reusing panel. Please see the attachment for the Snapshot of GUI.
Debug.pptx

@newville
Copy link
Owner

newville commented Jan 4, 2019

@Spandyie Well, I have no idea what your code does or is supposed to do. That makes it essentially impossible to guess what you are seeing that you do not expect.

Am I supposed to see something in the pptx file? What, exactly? No, really, if you want me to know, you need to tell me explicitly. I cannot tell if you are trying to illustrate a bug or ask how to do something. Please post a minimal, complete (working) code that illustrates the problem.

@Spandyie
Copy link
Author

Spandyie commented Jan 15, 2019

Solved the Problem apparently I had to destroy the all the children panel in the parent panel to solve the issue
following lines of code above super().init() solve it:
for child in parent_panel.GetChildren(): child.Destroy()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants