5252colormaps = sorted (m for m in plt .cm .datad if not m .endswith ("_r" ))
5353markers = ['' ,'o' ,'.' ,'^' ,'v' ,'>' ,'<' ,'s' ,'+' ,'x' ,'p' ,'d' ,'h' ,'*' ]
5454linestyles = ['-' ,'--' ,'-.' ,':' ]
55+ plotkinds = ['line' , 'bar' , 'barh' , 'scatter' , 'pie' , 'histogram' , 'boxplot' , 'violinplot' , 'dotplot' ,
56+ 'heatmap' , 'area' , 'hexbin' , 'scatter_matrix' , 'density' , 'radviz' ]
5557valid_kwds = {'line' : ['alpha' , 'colormap' , 'grid' , 'legend' , 'linestyle' ,'ms' ,
5658 'linewidth' , 'marker' , 'subplots' , 'rotx' , 'logx' , 'logy' ,
5759 'sharex' ,'sharey' , 'kind' ],
@@ -139,7 +141,7 @@ def __init__(self, table, parent=None):
139141 self .table = table
140142 self .createWidgets ()
141143 self .createOptions ()
142- self .seriesopts = SeriesOptions (plotviewer = self )
144+ # self.seriesopts = SeriesOptions(plotviewer=self)
143145 self .currentdir = os .path .expanduser ('~' )
144146 sizepolicy = QSizePolicy ()
145147 self .setSizePolicy (QSizePolicy (QSizePolicy .Expanding , QSizePolicy .Expanding ))
@@ -157,7 +159,7 @@ def addPlotWidget(self):
157159 self .toolbar = NavigationToolbar (self .canvas , layout )
158160
159161 #add custom buttons
160- iconfile = os .path .join (iconpath ,'plotseries.png' )
162+ # iconfile = os.path.join(iconpath,'plotseries.png')
161163 #a = QAction(QIcon(iconfile), "Customise Series", self)
162164 #a.triggered.connect(self.customiseSeries)
163165 #self.toolbar.addAction(a)
@@ -173,38 +175,68 @@ def addPlotWidget(self):
173175 vbox .addWidget (self .canvas )
174176 return
175177
178+ def updateSeries (self , event = None ):
179+ """Update series with new plots"""
180+
181+ data = self .table .getSelectedDataFrame ()
182+ self .seriesopts .series = self .getSeries (data )
183+ return
184+
176185 def customiseSeries (self ):
177186 """
178187 Show custom options for current plot series. Allows plot types to
179188 be specified per series and uses a custom plot function.
180189 """
181190
182- data = self .table .getSelectedDataFrame ()
183191 if self .seriesopts .series == {}:
184- self .seriesopts . series = self . getSeries ( data )
192+ self .updateSeries ( )
185193 dlg = self .seriesopts .showDialog (self )
186194 dlg .exec_ ()
187195 return
188196
189197 def customPlot (self ):
190198 """plot custom series """
191199
200+ self .applyPlotoptions ()
201+ self .setStyle ()
202+ kwds = self .opts ['general' ].kwds
203+ formatkwds = self .opts ['format' ].kwds
204+ kwds .update (formatkwds )
205+ axes_layout = kwds ['axes_layout' ]
206+ lkwds = self .opts ['labels' ].kwds .copy ()
207+ axkwds = self .opts ['axes' ].kwds
208+
192209 data = self .table .getSelectedDataFrame ()
193210 layout = 'single'
194211 self .clear ()
195212 self .ax = self .fig .add_subplot (111 )
196213 series = self .seriesopts .series
197214 for s in series :
198215 df = data [s ]
199- kwds = series [s ]
200- kind = kwds ['kind' ]
201- color = kwds [ 'color' ]
202- print (kwds )
203- df .plot (kind = kind , layout = layout ,color = color , ax = self .ax )
216+ skwds = series [s ]
217+ kind = skwds ['kind' ]
218+ #skwds = self.check_kwds(skwds, kind)
219+ # print (skwds )
220+ df .plot (layout = layout ,ax = self .ax , ** skwds )
204221 self .fig .legend ()
222+
223+ axs = self .ax
224+ lkwds .update (kwds )
225+ self .setFigureOptions (axs , lkwds )
205226 self .canvas .draw ()
206227 return
207228
229+ def check_kwds (self , kwds , kind ):
230+ return dict ((k , kwds [k ]) for k in valid_kwds [kind ] if k in kwds )
231+
232+ def colorsfromColormap (self , df , cmap ):
233+ """Column colors from cmap"""
234+
235+ cols = df .columns
236+ clrs = util .gen_colors (cmap ,len (cols ))
237+ colordict = dict (zip (cols ,clrs ))
238+ return colordict
239+
208240 def showTools (self ):
209241 """Show/hide tools dock"""
210242
@@ -217,7 +249,6 @@ def showTools(self):
217249 def createWidgets (self ):
218250 """Create widgets. Plot on left and dock for tools on right."""
219251
220- #self.main = QSplitter(Qt.Horizontal, self)
221252 self .main = QWidget (self )
222253 hbox = QHBoxLayout (self )
223254 self .left = left = QWidget (self .main )
@@ -301,8 +332,7 @@ def replot(self, data=None):
301332 self .data = data
302333
303334 self .applyPlotoptions ()
304- #self.getSeries(data)
305-
335+ #self.updateSeries()
306336 self .setStyle ()
307337 self .plotCurrent ()
308338 return
@@ -325,13 +355,20 @@ def plotCurrent(self, redraw=True):
325355 def getSeries (self , data ):
326356
327357 kwds = self .opts ['general' ].kwds
328- ptype = kwds ['kind' ]
358+ fkwds = self .opts ['format' ].kwds
359+ kwds .update (fkwds )
329360 self .series = series = {}
361+ colordict = self .colorsfromColormap (data , fkwds ['colormap' ])
362+ #print (colordict)
363+ basekwds = ['kind' ,'marker' ,'ms' ,'linestyle' , 'linewidth' , 'alpha' ]
364+ skwds = {k :kwds [k ] for k in basekwds }
365+ #print (fkwds)
330366 for c in data .columns :
331- series [c ] = {}
332- series [c ]['kind' ] = ptype
333- series [c ]['color' ] = ''
334- #print (self.series)
367+ series [c ] = skwds .copy ()
368+ #series[c]['kind'] = kind
369+ series [c ]['color' ] = colordict [c ]
370+ print (series [c ])
371+ print (self .series )
335372 return series
336373
337374 def applyPlotoptions (self ):
@@ -838,7 +875,7 @@ def _doplot(self, data, ax, kind, axes_layout, errorbars, useindex, bw, yerr,
838875 return
839876 #adjust colormap to avoid white lines
840877 if cmap != None :
841- cmap = util .adjustColorMap (cmap , 0.15 ,1.0 )
878+ # cmap = util.adjustColorMap(cmap, 0.15,1.0)
842879 del kwargs ['colormap' ]
843880 if kind == 'barh' :
844881 kwargs ['xerr' ]= yerr
@@ -1456,8 +1493,6 @@ class MPLBaseOptions(BaseOptions):
14561493 """Class to provide a dialog for matplotlib options and returning
14571494 the selected prefs"""
14581495
1459- kinds = ['line' , 'bar' , 'barh' , 'scatter' , 'pie' , 'histogram' , 'boxplot' , 'violinplot' , 'dotplot' ,
1460- 'heatmap' , 'area' , 'hexbin' , 'scatter_matrix' , 'density' , 'radviz' ]
14611496 legendlocs = ['best' ,'upper right' ,'upper left' ,'lower left' ,'lower right' ,'right' ,'center left' ,
14621497 'center right' ,'lower center' ,'upper center' ,'center' ]
14631498
@@ -1484,7 +1519,7 @@ def __init__(self):
14841519 'sharex' :{'type' :'checkbox' ,'default' :0 ,'label' :'share x' },
14851520 'sharey' :{'type' :'checkbox' ,'default' :0 ,'label' :'share y' },
14861521 'legend' :{'type' :'checkbox' ,'default' :1 ,'label' :'legend' },
1487- 'kind' :{'type' :'combobox' ,'default' :'line' ,'items' :self . kinds ,'label' :'plot type' },
1522+ 'kind' :{'type' :'combobox' ,'default' :'line' ,'items' :plotkinds ,'label' :'plot type' },
14881523 'stacked' :{'type' :'checkbox' ,'default' :0 ,'label' :'stacked' },
14891524 'axes_layout' :{'type' :'combobox' ,'default' :'single' ,'items' :layouts ,'label' :'axes layout' },
14901525 'bins' :{'type' :'spinbox' ,'default' :20 ,'width' :5 },
@@ -1686,27 +1721,33 @@ def createSeriesWidgets(self, parent):
16861721
16871722 l = parent .layout
16881723 l .setAlignment (QtCore .Qt .AlignTop )
1689- kinds = [ 'line' , 'bar' , 'scatter' ]
1724+
16901725 row = QWidget ()
16911726 l .addWidget (row )
16921727 l2 = QHBoxLayout (row )
1693- l2 .addWidget (QLabel ('name' ))
1694- l2 .addWidget (QLabel ('kind' ))
1695- l2 .addWidget (QLabel ('color' ))
1696- l2 .addWidget (QLabel ('linestyle' ))
1728+ for i in ['name' ,'kind' ,'color' ,'line style' ,'marker' ,'marker size' ,'alpha' ]:
1729+ w = QLabel (i )
1730+ l2 .addWidget (w )
1731+ #w.setFixedWidth(100)
1732+ kinds = ['line' ,'bar' ]
16971733 self .widgets = {}
16981734 for s in self .series :
16991735 self .widgets [s ] = {}
17001736 opt = self .series [s ]
17011737 row = QWidget ()
17021738 l .addWidget (row )
17031739 l2 = QHBoxLayout (row )
1704- l2 .addWidget (QLabel (s ))
1740+ w = QLabel (s )
1741+ w .setFixedWidth (100 )
1742+ l2 .addWidget (w )
17051743 w = QComboBox ()
17061744 w .addItems (kinds )
17071745 val = self .series [s ]['kind' ]
17081746 index = w .findText (val )
17091747 w .setCurrentIndex (index )
1748+ w .setFixedWidth (80 )
1749+ if val not in ['line' ,'bar' ]:
1750+ w .setEnabled (False )
17101751 l2 .addWidget (w )
17111752 self .widgets [s ]['kind' ] = w
17121753 w = ColorButton ()
@@ -1716,8 +1757,36 @@ def createSeriesWidgets(self, parent):
17161757 self .widgets [s ]['color' ] = w
17171758 w = QComboBox ()
17181759 w .addItems (linestyles )
1760+ val = self .series [s ]['linestyle' ]
1761+ index = w .findText (val )
1762+ w .setCurrentIndex (index )
17191763 l2 .addWidget (w )
17201764 self .widgets [s ]['linestyle' ] = w
1765+ w = QSpinBox ()
1766+ val = self .series [s ]['linewidth' ]
1767+ w .setValue (int (val ))
1768+ l2 .addWidget (w )
1769+ self .widgets [s ]['linewidth' ] = w
1770+ w = QComboBox ()
1771+ w .addItems (markers )
1772+ val = self .series [s ]['marker' ]
1773+ index = w .findText (val )
1774+ w .setCurrentIndex (index )
1775+ self .widgets [s ]['marker' ] = w
1776+ l2 .addWidget (w )
1777+ w = QSpinBox ()
1778+ val = self .series [s ]['ms' ]
1779+ w .setValue (int (val ))
1780+ l2 .addWidget (w )
1781+ self .widgets [s ]['ms' ] = w
1782+ w = QDoubleSpinBox ()
1783+ val = self .series [s ]['alpha' ]
1784+ w .setValue (val )
1785+ w .setRange (0 ,1 )
1786+ w .setSingleStep (0.1 )
1787+ l2 .addWidget (w )
1788+ self .widgets [s ]['alpha' ] = w
1789+
17211790 return
17221791
17231792 def update (self , event = None ):
@@ -1727,37 +1796,12 @@ def update(self, event=None):
17271796 for i in self .widgets [s ]:
17281797 w = self .widgets [s ][i ]
17291798 val = getWidgetValue (w )
1730- #print (val)
1799+ #print (s,i, val)
17311800 self .series [s ][i ] = val
1732- print (self .series )
1801+ # print (self.series)
17331802 self .plotviewer .customPlot ()
17341803 return
17351804
17361805 def close (self ):
17371806 self .dlg .destroy ()
17381807 return
1739-
1740- class CustomiseDialog (QDialog ):
1741- """Preferences dialog from config parser options"""
1742-
1743- def __init__ (self , parent , options = {}):
1744-
1745- super (CustomiseDialog , self ).__init__ (parent )
1746- self .parent = parent
1747- self .setWindowTitle ('Custom plot' )
1748- self .resize (400 , 200 )
1749- self .setGeometry (QtCore .QRect (300 ,300 , 600 , 200 ))
1750- self .setMaximumWidth (600 )
1751- self .setMaximumHeight (300 )
1752- self .show ()
1753- return
1754-
1755- def createWidgets (self ):
1756- """create widgets"""
1757-
1758- self .tabs = QTabWidget ()
1759- l = self .layout = QVBoxLayout (self )
1760- l .addWidget (self .tabs )
1761- w = QWidget ()
1762- idx = self .tabs .addTab (w , 'legend' )
1763- return
0 commit comments