Commit 39dac300 authored by eric pellegrini's avatar eric pellegrini
Browse files

Bug fix in Plotter when plotting 2D data with one dimension equal to 1

Removed unused imports
parent dfedb15a
......@@ -445,7 +445,7 @@ class Plotter1D(wx.Panel):
self.figure.gca().legend(tuple(legend[0]), tuple(legend[1]), loc = self.legend_location, frameon = self.legend_frameon, shadow = self.legend_shadow, fancybox = self.legend_fancybox)
self.show_legend = True
def Plot(self, data, varname):
def plot(self, data, varname):
if data is None:
return
self.set_axis_property(varname, data)
......
......@@ -104,14 +104,7 @@ class Plotter2D(wx.Panel):
self.slice_coords = []
self.slice_widget = []
# self.segment_slice_canvas = None
# self.segment_slice_dialog = None
# self.segment_slice_plot = None
# self.segment_slice_fig = None
# self.segment_slice_color_index = 0
# self.segment_slice_legend = []
self.cross_slice_canvas = None
self.cross_slice_dialog = None
self.h_cross_slice_plot = None
......@@ -429,19 +422,27 @@ class Plotter2D(wx.Panel):
return vslice, hslice
def set_lim(self):
self.Xmin, self.Xmax = self.Xaxis[0], self.Xaxis[-1]
if self.Xmin == self.Xmax:
self.Xmin -= 1.0e-9
self.Xmax += 1.0e-9
self.Ymin, self.Ymax = self.Yaxis[0], self.Yaxis[-1]
if self.Ymin == self.Ymax:
self.Ymin -= 1.0e-9
self.Ymax += 1.0e-9
def reset_axis(self):
self.set_lim()
self.figure.gca().axis([self.Xmin, self.Xmax, self.Ymin, self.Ymax])
self.figure.gca().axis([self.Xmin, self.Xmax, self.Ymin, self.Ymax])
self.canvas.draw()
def Plot(self, data, varname, Xaxis = None, Xunit = None, Yaxis = None, Yunit = None, transposition = True):
def plot(self, data, varname, Xaxis = None, Xunit = None, Yaxis = None, Yunit = None, transposition = True):
if data is None:
return
if not (Xaxis != None and Xunit != None and Yaxis != None and Yunit != None):
if ((Xaxis is None) or (Xunit is None) or (Yaxis is None) or (Yunit is None)):
self.set_axis_property(varname,data)
else:
self.Xaxis = Xaxis
......@@ -457,10 +458,9 @@ class Plotter2D(wx.Panel):
self.varname = varname
self.subplot = self.figure.add_subplot( 111 )
self.ax = self.subplot.imshow(self.data, interpolation=self.interpolation, origin='lower')
self.subplot.set_aspect('auto')
self.aspect = 'auto'
......@@ -468,7 +468,8 @@ class Plotter2D(wx.Panel):
self.Ylabel = self.Yaxis_label
self.figure.gca().set_xlabel(self.Xlabel + self.fmt_Xunit )
self.figure.gca().set_ylabel(self.Ylabel + self.fmt_Yunit )
self.set_lim()
self.set_ticks()
self.reset_axis()
......@@ -476,7 +477,7 @@ class Plotter2D(wx.Panel):
self.canvas.draw()
def rePlot(self, oldinstance):
def replot(self, oldinstance):
self.data = oldinstance.data
self.Xaxis = oldinstance.Xaxis
......@@ -529,9 +530,10 @@ class Plotter2D(wx.Panel):
def compute_conversion_factor(self):
try:
self.Xunit_conversion_factor = magnitude.mg(1., self.Xinit_unit, self.Xunit).toval()
except magnitude.MagnitudeError:
except magnitude.MagnitudeError:
self.Xunit_conversion_factor = 1.0
try:
......@@ -543,14 +545,14 @@ class Plotter2D(wx.Panel):
def set_ticks(self):
self.compute_conversion_factor()
self.figure.gca().xaxis.set_major_locator(ScaledLocator(dx = self.Xunit_conversion_factor))
self.figure.gca().xaxis.set_major_formatter(ScaledFormatter(dx = self.Xunit_conversion_factor))
self.figure.gca().yaxis.set_major_locator(ScaledLocator(dx = self.Yunit_conversion_factor))
self.figure.gca().yaxis.set_major_formatter(ScaledFormatter(dx = self.Yunit_conversion_factor))
self.ax.set_extent([self.Xaxis[0], self.Xaxis[-1], self.Yaxis[0], self.Yaxis[-1]])
self.ax.set_extent([self.Xmin, self.Xmax, self.Ymin, self.Ymax])
def set_axis_property(self, varname, data):
oldXunit = self.Xinit_unit
......
......@@ -170,10 +170,10 @@ class DataPanel(wx.Panel):
qviewPanel = wx.Panel(self)
sb_sizer2 = wx.BoxSizer(wx.VERTICAL)
self.QV_Figure = Figure(figsize=(1,1))
self.QV_Canvas = FigureCanvasWxAgg(qviewPanel, wx.ID_ANY, self.QV_Figure)
self.QV_Plot = self.QV_Figure.add_axes([0.01,0.01,0.98,0.98])
sb_sizer2.Add(self.QV_Canvas, 1, wx.ALL|wx.EXPAND, 2)
self.qvFigure = Figure(figsize=(1,1))
self.qvCanvas = FigureCanvasWxAgg(qviewPanel, wx.ID_ANY, self.qvFigure)
self.qvPlot = self.qvFigure.add_axes([0.01,0.01,0.98,0.98])
sb_sizer2.Add(self.qvCanvas, 1, wx.ALL|wx.EXPAND, 2)
qviewPanel.SetSizer(sb_sizer2)
sb_sizer2.Fit(qviewPanel)
......@@ -265,23 +265,23 @@ class DataPanel(wx.Panel):
self.plot_type.SetStringSelection(types[-1])
self.selectedVar = var
self.QV_plot(data)
self.plot_quickview(data)
def QV_plot(self, data):
self.QV_Plot.clear()
def plot_quickview(self, data):
self.qvPlot.clear()
ndim = data.ndim
if ndim == 1:
self.QV_Plot.plot(data)
self.QV_Figure.gca().legend((self.selectedVar,None), loc = 'best', frameon = True, shadow = True, fancybox = False)
self.qvPlot.plot(data)
self.qvFigure.gca().legend((self.selectedVar,None), loc = 'best', frameon = True, shadow = True, fancybox = False)
elif ndim == 2:
self.QV_Plot.imshow(data.T, interpolation='nearest', origin='lower')
self.qvPlot.imshow(data.T, interpolation='nearest', origin='lower')
else:
self.QV_Plot.text(0.1, 0.5, 'No QuickView for data with dimension > 2 ')
self.QV_Plot.set_aspect('auto', 'datalim')
self.qvPlot.text(0.1, 0.5, 'No QuickView for data with dimension > 2 ')
self.qvPlot.set_aspect('auto')
self.QV_Canvas.draw()
self.qvCanvas.draw()
def on_plot(self, event=None):
if self.selectedVar is None:
......@@ -292,12 +292,12 @@ class DataPanel(wx.Panel):
if plot_type == 'Line':
Plotter = Plotter1D(self)
self.plotterNotebook.AddPage(Plotter, "%s(%s)"%(self.selectedVar,plot_type))
Plotter.Plot(data, self.selectedVar)
Plotter.plot(data, self.selectedVar)
elif plot_type == 'Image':
Plotter = Plotter2D(self)
self.plotterNotebook.AddPage(Plotter, "%s(%s)"%(self.selectedVar,plot_type))
Plotter.Plot(data, self.selectedVar)
Plotter.plot(data, self.selectedVar)
elif plot_type == 'Elevation':
Plotter = Plotter3D(self.parent)
......@@ -325,13 +325,13 @@ class DataPanel(wx.Panel):
plot_type = self.plot_type.GetValue()
if plot_type == 'Line' and self.selectedPlot.type == 'line':
data = self.dataproxy[self.selectedVar]['data']
self.selectedPlot.Plot(data, self.selectedVar)
self.selectedPlot.plot(data, self.selectedVar)
if plot_type == 'Image' and self.selectedPlot.type == 'image':
data = self.dataproxy[self.selectedVar]['data']
if hasattr(self.selectedPlot, 'AddPane'):
Plotter = Plotter2D(self.selectedPlot)
Plotter.Plot(data, self.selectedVar)
Plotter.plot(data, self.selectedVar)
self.selectedPlot.AddPane(Plotter, wxaui.AuiPaneInfo().Right().CloseButton(True).CaptionVisible(True).Caption(self.selectedVar).MinSize((200,-1)))
self.selectedPlot.Update()
else:
......@@ -340,10 +340,10 @@ class DataPanel(wx.Panel):
multiplot = MultiViewPanel(self)
NewPlotter = Plotter2D(multiplot)
NewPlotter.Plot(data, self.selectedVar)
NewPlotter.plot(data, self.selectedVar)
OldPlotter = Plotter2D(multiplot)
OldPlotter.rePlot(self.selectedPlot)
OldPlotter.replot(self.selectedPlot)
multiplot.AddPane(NewPlotter, wxaui.AuiPaneInfo().Right().CloseButton(True).CaptionVisible(True).Caption(self.selectedVar).MinSize((200,-1)))
multiplot.AddPane(OldPlotter, wxaui.AuiPaneInfo().Center().CloseButton(True).CaptionVisible(True).Caption(self.selectedPlot.varname))
......
......@@ -35,7 +35,7 @@ import os
import wx
import wx.grid as wxgrid
from MDANSE import ELEMENTS, LOGGER
from MDANSE import ELEMENTS
from MDANSE.Core.Singleton import Singleton
class PropertyDialog(wx.Dialog):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment