简体   繁体   English

使用 wxmplot 交互模块放大 plot 后如何访问数据?

[英]How can I access the data after zooming in a plot using wxmplot interactive module?

I am creating a script to interactively explore data visualizations using wxPython and wxmPlot.interactive module .我正在创建一个脚本来使用 wxPython 和wxmPlot.interactive 模块交互式地探索数据可视化。

When a file is opened after the Open Button is pressed using a wxPython FileDialog, it is read into a pandas DataFrame.当使用 wxPython FileDialog 按下打开按钮后打开文件时,它会被读入 pandas DataFrame。 Pressing the Plot Button results in the data being plotted on an interactive plot.按下 Plot 按钮会导致数据绘制在交互式 plot 上。 If I can access the x values for the new plot when clicking on the plot and dragging to select an area of interest, I will be able to find the matching y coordinates in the pandas DataFrame. If I can access the x values for the new plot when clicking on the plot and dragging to select an area of interest, I will be able to find the matching y coordinates in the pandas DataFrame. Or is there a direct way to access x and y limits on the zoomed plot using the returned PlotFrame object from the plot() method?或者是否有直接的方法可以使用 plot() 方法返回的 PlotFrame object 访问缩放后的 plot 的 x 和 y 限制? So far I can open a csv file, plot it and zoom in a region of interest.到目前为止,我可以打开一个 csv 文件 plot 并放大感兴趣的区域。 What I need is to understand how to get the coordinates of the new zoomed in plot in order to save the corresponding data to a file with just that data in the zoomed region.我需要了解如何在 plot 中获取新的缩放坐标,以便将相应的数据保存到仅在缩放区域中包含该数据的文件中。 Any help with this would be greatly appreciated.对此的任何帮助将不胜感激。

My code is as follows:我的代码如下:

import wx
import pandas as pd
import wxmplot.interactive as wi
import os

class MyFrame(wx.Frame):    
    def __init__(self):
        super().__init__(parent=None, title="Data Exploration Tool ")
        panel = wx.Panel(self)
        self.df = None
        self.title = ''
        my_sizer = wx.BoxSizer(wx.HORIZONTAL)        
        open_btn = wx.Button(panel, label='Open')
        open_btn.Bind(wx.EVT_BUTTON, self.OnOpen)
        my_sizer.Add(open_btn, 0, wx.ALL | wx.CENTER, 5)        
        plot_btn = wx.Button(panel, label='Plot')
        plot_btn.Bind(wx.EVT_BUTTON, self.OnPlot)
        my_sizer.Add(plot_btn, 0, wx.ALL | wx.CENTER, 5)        
        panel.SetSizer(my_sizer)        
        self.Show()
       
    def OnPlot(self, event):
        x = pd.to_datetime(self.df.iloc[:, 0], format='%m/%d/%y %H:%M %p' )
        for i in range(1, len(self.df.columns)):
            wi.plot(x, self.df.iloc[:, i], show_legend=True, 
                    title=self.title, wintitle=self.title)
                 
    def OnOpen(self, event):
        #  ask the user what new file to open
        defDir=''
        defFile=''
        fileDialog = wx.FileDialog(self, "Open CSV file", 
                        defDir, defFile,
                        wildcard="(*.csv;*.xlsx)|*.csv;*.xlsx",
                        style=wx.FD_OPEN | wx.FD_FILE_MUST_EXIST)
        if fileDialog.ShowModal() == wx.ID_CANCEL:
            return     # the user changed their mind
        # Proceed loading the file chosen by the user
        pathname = fileDialog.GetPath()
        print(pathname)
     
        self.df = pd.read_csv(pathname, skiprows=12, parse_dates=True)
        self.title = os.path.basename(pathname) 
    
if __name__ == '__main__':
    app = wx.App()

    frame = MyFrame()
    app.MainLoop()

  

You can get the limits for the "current view" with something like this:您可以通过以下方式获得“当前视图”的限制:

import numpy as np
import wxmplot.interactive as wi
x = np.linspace(-20, 20, 601)
y = np.sin(x/4.5) + x/50

display = wi.plot(x, y, label='test')

# now do some zooming, panning, etc

print(display.panel.get_viewlimits())

which might print something like:这可能会打印出类似的内容:

(-21.0, 21.0, -1.2026941911431666, 1.2026941911431666) (-21.0、21.0、-1.2026941911431666、1.2026941911431666)

I think that is what you are looking for.认为这就是你要找的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM