这有点复杂,但我会尝试
我有一个用于选择文件的面板或按钮“文件”,并且该文件的打开方式是一个 .nc 文件(netCDF4),所以我想将其可视化,但我想在另一个面板中看到它的问题这就像一个快速浏览,每次你必须选择一个 .nc 类型的文件或直接在另一个面板上可视化
这是我的 2 个面板代码的一部分:
class LeftPanelTop(wx.Panel): # panel choose file
def __init__(self, parent):
super().__init__(parent,style = wx.SUNKEN_BORDER)
self.SetBackgroundColour('snow2')
List_choices = ["1Km","3Km"]
List2 = ["3X3","5X5","7X7"]
self.dateLbl = wx.StaticBox(self, -1, 'Outils ', size=(310, 320))
self.dategraphSizer = wx.StaticBoxSizer(self.dateLbl, wx.VERTICAL)
combobox1 = wx.ComboBox(self,choices = List_choices, size =(80,20),pos =(180,50))
combobox2 = wx.ComboBox(self,choices = List2, size =(80,20),pos =(180,90))
wx.StaticText(self, label='Referen:', pos=(70, 50))
wx.StaticText(self, label='pixel:', pos=(70, 90))
QuickLook = wx.Button(self ,-1, "Open file" , size =(80, 25),pos =(180,130))
wx.StaticText(self, label='QuickLook:', pos=(70, 130))
QuickLook.Bind(wx.EVT_BUTTON, self.onOpen)
def onOpen(self, event):
wildcard = "netCDF4 files (*.nc)|*.nc"
dialog = wx.FileDialog(self, "Open netCDF4 Files| HDF5 files", wildcard=wildcard,
style=wx.FD_OPEN | wx.FD_FILE_MUST_EXIST)
if dialog.ShowModal() == wx.ID_CANCEL:
return
path = dialog.GetPath()
# panel for visualization
class LeftPanelBottom(wx.Panel):
def __init__(self, parent):
super().__init__(parent,style = wx.SUNKEN_BORDER)
self.SetBackgroundColour('whitesmoke')
self.dateLbl = wx.StaticBox(self, -1, 'QuickLook', size=(310, 600))
它在 python3.6 中读取和查看 netcdf4 的代码:
import numpy as np
import netCDF4
import matplotlib.pyplot as plt
#read the netcdf
fic='g_xvxvxvxv_20190108T120000Z.nc'
path='/home/globe/2019/01/08/'
nc = netCDF4.Dataset(path+fic,'r')
#read one variable in netcfd file
cm=nc.variables['cm'][:]
#visualization
plt.pcolormesh(cm)
plt.colorbar()
plt.show()
我会在 panel2 中看到 quicklook:
[![在此处输入图像描述][1]][1]
我想做的是使用我的代码来读取我的代码中的 .nc 并且我的用户可以选择一个文件,然后在另一个 panel2 上自动显示:
[![在此处输入图像描述][2]][2]
也许就像这个例子:How to use matplotlib blitting to add matplot.patches to an matplotlib plot in wxPython?
感谢您的帮助