Skip to content

Commit

Permalink
Merge pull request #195 from L-A-F/issue194
Browse files Browse the repository at this point in the history
add XYplot for 1D-array
  • Loading branch information
giumas authored Aug 14, 2019
2 parents 945d9ac + a14277c commit 050e05a
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
18 changes: 16 additions & 2 deletions hdf_compass/compass_viewer/array/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
log = logging.getLogger(__name__)

from ..frame import NodeFrame
from .plot import LinePlotFrame, ContourPlotFrame
from .plot import LinePlotFrame, LineXYPlotFrame, ContourPlotFrame


# Indicates that the slicing selection may have changed.
Expand All @@ -37,6 +37,7 @@

# Menu and button IDs
ID_VIS_MENU_PLOT = wx.NewId()
ID_VIS_MENU_PLOTXY = wx.NewId()
ID_VIS_MENU_COPY = wx.NewId()
ID_VIS_MENU_EXPORT = wx.NewId()

Expand Down Expand Up @@ -72,6 +73,7 @@ def __init__(self, node, pos=None):
vis_menu = wx.Menu()
if self.node.is_plottable():
vis_menu.Append(ID_VIS_MENU_PLOT, "Plot Data\tCtrl-D")
vis_menu.Append(ID_VIS_MENU_PLOTXY, "Plot XY\tCtrl-T")
self.add_menu(vis_menu, "Visualize")
# Initialize the toolbar
self.init_toolbar()
Expand All @@ -91,6 +93,7 @@ def __init__(self, node, pos=None):
self.Bind(EVT_ARRAY_SELECTED, self.on_selected)
if self.node.is_plottable():
self.Bind(wx.EVT_MENU, self.on_plot, id=ID_VIS_MENU_PLOT)
self.Bind(wx.EVT_MENU, self.on_plotxy, id=ID_VIS_MENU_PLOTXY)

self.Bind(wx.EVT_MENU, self.on_copy, id=ID_VIS_MENU_COPY)
self.Bind(wx.EVT_MENU, self.on_export, id=ID_VIS_MENU_EXPORT)
Expand All @@ -105,6 +108,7 @@ def init_toolbar(self):
""" Set up the toolbar at the top of the window. """
t_size = (24, 24)
plot_bmp = wx.Bitmap(os.path.join(self.icon_folder, "viz_plot_24.png"), wx.BITMAP_TYPE_ANY)
plot_xy_bmp = wx.Bitmap(os.path.join(self.icon_folder, "viz_plot_xy_24.png"), wx.BITMAP_TYPE_ANY)
copy_bmp = wx.Bitmap(os.path.join(self.icon_folder, "viz_copy_24.png"), wx.BITMAP_TYPE_ANY)
export_bmp = wx.Bitmap(os.path.join(self.icon_folder, "save_24.png"), wx.BITMAP_TYPE_ANY)

Expand All @@ -131,7 +135,9 @@ def init_toolbar(self):
self.toolbar.AddLabelTool(ID_VIS_MENU_PLOT, "Plot Data", plot_bmp,
shortHelp="Plot data in a popup window",
longHelp="Plot the array data in a popup window")

self.toolbar.AddLabelTool(ID_VIS_MENU_PLOTXY, "Plot XY", plot_xy_bmp,
shortHelp="Plot data against first row",
longHelp="Plot data against first selected row in a popup window")
self.toolbar.Realize()


Expand Down Expand Up @@ -235,6 +241,14 @@ def on_plot(self, evt):
f = ContourPlotFrame(data)
f.Show()

def on_plotxy(self, evt):
""" User has chosen to plot the current selection against first selected row"""
data, names, line = self.get_selected_data()
if data != None and len(data) != 1:
if line:
f = LineXYPlotFrame(data, names)
f.Show()

def on_copy(self, evt):
""" User has chosen to copy the current selection to the clipboard """

Expand Down
19 changes: 18 additions & 1 deletion hdf_compass/compass_viewer/array/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ def __init__(self, data, title="a title"):
self.canvas = FigCanvas(self.panel, -1, self.fig)

self.axes = self.fig.add_subplot(111)
self.axes.set_xlabel('')
self.axes.set_ylabel('')

self.toolbar = NavigationToolbar(self.canvas)

self.vbox = wx.BoxSizer(wx.VERTICAL)
Expand All @@ -78,12 +81,26 @@ def __init__(self, data, names=None, title="Line Plot"):
PlotFrame.__init__(self, data, title)

def draw_figure(self):

lines = [self.axes.plot(d)[0] for d in self.data]
if self.names is not None:
for n in self.names:
self.axes.legend(tuple(lines), tuple(self.names))

class LineXYPlotFrame(PlotFrame):
def __init__(self, data, names=None, title="Line XY Plot"):
self.names = names
PlotFrame.__init__(self, data, title)

def draw_figure(self):
self.axes.set_xlabel(self.names[0])
if len(self.data)==2:
# a simple X-Y plot using 2 columns
self.axes.set_ylabel(self.names[1])

lines = [self.axes.plot(self.data[0], d)[0] for d in self.data[1::]]
if self.names is not None:
for n in self.names:
self.axes.legend(tuple(lines), tuple(self.names[1::]))

class ContourPlotFrame(PlotFrame):
def __init__(self, data, names=None, title="Contour Plot"):
Expand Down
Binary file added hdf_compass/compass_viewer/icons/viz_plot_xy_24.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 050e05a

Please sign in to comment.