Skip to content

Commit

Permalink
dpi fix
Browse files Browse the repository at this point in the history
  • Loading branch information
dmnfarrell committed Oct 4, 2021
1 parent dec8888 commit 3e25d8b
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 32 deletions.
5 changes: 4 additions & 1 deletion CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@
* fix to saving when filtered
* align header labels left
* remember current sheet when saving
* added enlarge/reduce buttons to plotter
* added enlarge/reduce buttons to plot toolbar
* icon size preference
* fix to plot style
* format date index
* sort by index
* moved dpi to preferences

-----
0.4.0
Expand Down
12 changes: 9 additions & 3 deletions tablexplore/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ def loadSettings(self):
core.TIMEFORMAT = s.value("timeformat")
core.SHOWPLOTTER = util.valueToBool(s.value("showplotter"))
core.PLOTSTYLE = s.value("plotstyle")
core.DPI = int(s.value("dpi"))
import matplotlib as mpl
mpl.rcParams['savefig.dpi'] = core.DPI
core.ICONSIZE = int(s.value("iconsize"))
r = s.value("recent_files")
if r != '':
Expand All @@ -131,6 +134,7 @@ def saveSettings(self):
self.settings.setValue('timeformat', core.TIMEFORMAT)
self.settings.setValue('showplotter', core.SHOWPLOTTER)
self.settings.setValue('plotstyle', core.PLOTSTYLE)
self.settings.setValue('dpi', core.DPI)
self.settings.setValue('recent_files',','.join(self.recent_files))
self.settings.setValue('recent_urls','^^'.join(self.recent_urls))
if hasattr(self, 'plotgallery'):
Expand All @@ -145,6 +149,8 @@ def applySettings(self):
for s in self.sheets:
table = self.sheets[s]
table.toolbar.setIconSize(QtCore.QSize(core.ICONSIZE, core.ICONSIZE))
import matplotlib as mpl
mpl.rcParams['savefig.dpi'] = core.DPI
return

def setStyle(self, style='default'):
Expand All @@ -161,6 +167,7 @@ def setStyle(self, style='default'):
return

def createToolBar(self):
"""Create main toolbar"""

items = {'new project': {'action': lambda: self.newProject(ask=True),'file':'document-new'},
'open': {'action':self.openProject,'file':'document-open'},
Expand All @@ -172,7 +179,6 @@ def createToolBar(self):
'add sheet': {'action': lambda: self.addSheet(name=None),'file':'add'},
'add column': {'action': lambda: self._call('addColumn'),'file':'add-column'},
'add row': {'action': lambda: self._call('addRows'),'file':'add-row'},
#'lock': {'action':self.lockTable,'file':'lock'},
'clean data': {'action':lambda: self._call('cleanData'),'file':'clean'},
'table to text': {'action':lambda: self._call('showAsText'),'file':'tabletotext'},
'table info': {'action':lambda: self._call('info'),'file':'tableinfo'},
Expand Down Expand Up @@ -712,7 +718,7 @@ def addSheet(self, name=None, df=None, meta=None):
dfw = DataFrameWidget(sheet, dataframe=df, app=self,
font=core.FONT, fontsize=core.FONTSIZE,
columnwidth=core.COLUMNWIDTH, timeformat=core.TIMEFORMAT)
sheet.addWidget(dfw)
sheet.addWidget(dfw)
self.sheets[name] = dfw
self.currenttable = dfw
pf = dfw.createPlotViewer(sheet)
Expand Down Expand Up @@ -1091,7 +1097,7 @@ def preferences(self):

from . import dialogs
opts = {'font':core.FONT, 'fontsize':core.FONTSIZE, 'showplotter': core.SHOWPLOTTER,
'iconsize':core.ICONSIZE, 'plotstyle':core.PLOTSTYLE,
'iconsize':core.ICONSIZE, 'plotstyle':core.PLOTSTYLE, 'dpi':core.DPI,
'columnwidth':core.COLUMNWIDTH, 'timeformat':core.TIMEFORMAT}
dlg = dialogs.PreferencesDialog(self, opts)
dlg.exec_()
Expand Down
1 change: 1 addition & 0 deletions tablexplore/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
SHOWPLOTTER = True
ICONSIZE = 26
PLOTSTYLE = 'default'
DPI = 100

try:
_fromUtf8 = QtCore.QString.fromUtf8
Expand Down
6 changes: 4 additions & 2 deletions tablexplore/dialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1146,7 +1146,7 @@ def __init__(self, parent, options={}):
super(PreferencesDialog, self).__init__(parent)
self.parent = parent
self.setWindowTitle('Preferences')
self.resize(450, 200)
self.resize(400, 200)
self.setGeometry(QtCore.QRect(300,300, 600, 200))
self.setMaximumWidth(600)
self.setMaximumHeight(300)
Expand Down Expand Up @@ -1184,12 +1184,13 @@ def createWidgets(self, options):
'showplotter': {'type':'checkbox','default':bool(options['showplotter']), 'label':'Show Plotter'},
'plotstyle':{'type':'combobox','default':options['plotstyle'],
'items':plotstyles,'label':'Plot Style'},
'dpi':{'type':'entry','default':100,'default':options['dpi'], 'label':'Plot DPI'},
'iconsize':{'type':'spinbox','default':options['iconsize'],'range':(16,64), 'label':'Icon Size'},
#'floatprecision':{'type':'spinbox','default':2, 'label':'precision'},
}
sections = {'table':['alignment','rowheight',#'columnwidth',
'font','fontsize','timeformat'],
'view':['iconsize','plotstyle','showplotter']
'view':['iconsize','plotstyle','dpi','showplotter']
}

dialog, self.widgets = dialogFromOptions(self, self.opts, sections)
Expand Down Expand Up @@ -1224,6 +1225,7 @@ def apply(self):
core.TIMEFORMAT = kwds['timeformat']
core.SHOWPLOTTER = kwds['showplotter']
core.PLOTSTYLE = kwds['plotstyle']
core.DPI = kwds['dpi']
core.ICONSIZE = kwds['iconsize']
self.parent.refresh()
self.parent.applySettings()
Expand Down
41 changes: 15 additions & 26 deletions tablexplore/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ def createDialogs(self, parent):
l.addWidget(dialog)'''
return tab

def createButtons(self, parent):
'''def createButtons(self, parent):
"""Create button widgets"""
buttons = {'Plot': {'action':self.plot,'icon':'plot'},
Expand Down Expand Up @@ -297,7 +297,7 @@ def createButtons(self, parent):
dialog.resize(200,200)
box.addWidget(dialog)
bw.setMaximumHeight(60)
return bw
return bw'''

def simple_plot(self, df):
"""test plot"""
Expand All @@ -322,6 +322,7 @@ def zoom(self, zoomin=True):

if len(self.generalopts.kwds) == 0:
return

self.generalopts.increment('linewidth',val)
self.generalopts.increment('ms',val)
self.labelopts.increment('fontsize',val)
Expand Down Expand Up @@ -375,7 +376,7 @@ def applyPlotoptions(self):
self.labelopts.applyOptions()
self.axesopts.applyOptions()
self.style = self.generalopts.kwds['style']
mpl.rcParams['savefig.dpi'] = self.generalopts.kwds['dpi']
#mpl.rcParams['savefig.dpi'] = self.generalopts.kwds['dpi']
return

def updateData(self):
Expand Down Expand Up @@ -408,8 +409,8 @@ def savePlot(self, filename=None):
"","png files (*.png);;jpg files (*.jpg)")
if filename:
self.currentdir = os.path.dirname(os.path.abspath(filename))
dpi = self.globalopts['dpi']
self.fig.savefig(filename, dpi=dpi)
#dpi = self.globalopts['dpi']
self.fig.savefig(filename, dpi=core.DPI)
return

def showWarning(self, text='plot error', ax=None):
Expand Down Expand Up @@ -811,6 +812,7 @@ def _doplot(self, data, ax, kind, axes_layout, errorbars, useindex, bw, yerr,
axs = plotting.bootstrap_plot(data)
elif kind == 'scatter_matrix':
kwargs['marker'] = 'o'
kwargs['s'] = 2
axs = plotting.scatter_matrix(data, ax=ax, **kwargs)
elif kind == 'hexbin':
x = cols[0]
Expand Down Expand Up @@ -1421,20 +1423,6 @@ def increment(self, key, inc):
self.setWidgetValue(key, new)
return

class GlobalOptions(BaseOptions):
"""Class to provide a dialog for global plot options"""

def __init__(self, parent=None):
"""Setup variables"""

self.parent = parent
self.groups = {'global': ['dpi','3D plot']}
self.opts = OrderedDict({ 'dpi': {'type':'spinbox','default':100,'width':4},
#'grid layout': {'type':'checkbox','default':0,'label':'grid layout'},
'3D plot': {'type':'checkbox','default':0,'label':'3D plot'} })
self.kwds = {}
return

class MPLBaseOptions(BaseOptions):
"""Class to provide a dialog for matplotlib options and returning
the selected prefs"""
Expand Down Expand Up @@ -1462,17 +1450,17 @@ def __init__(self, parent=None):
'grayscale','dark_background']
grps = {'data':['by','by2','labelcol','pointsizes'],
'formats':['marker','ms','linestyle','linewidth','alpha'],
'global':['dpi','3D plot'],
'general':['kind','axes_layout','bins','stacked','use_index','errorbars'],
'axes':['grid','legend','showxlabels','showylabels','sharex','sharey','logx','logy'],
'colors':['style','colormap','bw','clrcol','cscale','colorbar']}
order = ['general','data','axes','formats','colors','global']
'colors':['style','colormap','bw','clrcol','cscale','colorbar'],
'other':['3D plot']}
order = ['general','data','axes','formats','colors','other']
self.groups = OrderedDict((key, grps[key]) for key in order)
opts = self.opts = {
'style':{'type':'combobox','default':'default','items': style_list},
'marker':{'type':'combobox','default':'','items': markers},
'linestyle':{'type':'combobox','default':'-','items': linestyles},
'ms':{'type':'slider','default':5,'range':(1,80),'interval':1,'label':'marker size'},
'ms':{'type':'spinbox','default':5,'range':(1,80),'interval':1,'label':'marker size'},
'grid':{'type':'checkbox','default':0,'label':'show grid'},
'logx':{'type':'checkbox','default':0,'label':'log x'},
'logy':{'type':'checkbox','default':0,'label':'log y'},
Expand Down Expand Up @@ -1500,7 +1488,7 @@ def __init__(self, parent=None):
'by2':{'type':'combobox','items':datacols,'label':'group by 2','default':''},
'labelcol':{'type':'combobox','items':datacols,'label':'point labels','default':''},
'pointsizes':{'type':'combobox','items':datacols,'label':'point sizes','default':''},
'dpi': {'type':'spinbox','default':100,'width':4,'range':(10,300)},
# 'dpi': {'type':'spinbox','default':100,'width':4,'range':(10,300)},
'3D plot': {'type':'checkbox','default':0,'label':'3D plot'}
}
self.kwds = {}
Expand All @@ -1521,6 +1509,7 @@ def update(self, df):
self.widgets[name].addItems(cols)
return


class AnnotationOptions(BaseOptions):
"""This class also provides custom tools for adding items to the plot"""
def __init__(self, parent=None):
Expand Down Expand Up @@ -1727,7 +1716,7 @@ def save(self):
return

fig = self.plots[name]
fig.savefig(filename+'.png', dpi=100)
fig.savefig(filename+'.png', dpi=core.DPI)
return

def saveAll(self):
Expand All @@ -1739,7 +1728,7 @@ def saveAll(self):
return
for name in self.plots:
fig = self.plots[name]
fig.savefig(os.path.join(dir,name+'.png'), dpi=100)
fig.savefig(os.path.join(dir,name+'.png'), dpi=core.DPI)
return

def clear(self):
Expand Down

0 comments on commit 3e25d8b

Please sign in to comment.