Skip to content

Commit

Permalink
- make plot export consistent with matplotlib figure title
Browse files Browse the repository at this point in the history
- add ".png" to file name in export dialog (close #99)
- minor code cleanup
  • Loading branch information
Paul Müller committed Sep 17, 2015
1 parent bf3ce27 commit 08618d8
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 76 deletions.
1 change: 1 addition & 0 deletions ChangeLog.txt
Expand Up @@ -4,6 +4,7 @@
- The displayed Chi2-value for non-weighted fits is now
normalized to the expected values of the fit. The
documentation has been updated accordingly.
- Add "All files" option in save dialogs (#97)
0.8.9
- Improved support for "ALV-7004" files (#104)
- Increase resolution for image export
Expand Down
13 changes: 3 additions & 10 deletions pycorrfit/edclasses.py
Expand Up @@ -23,11 +23,8 @@
except:
pass


import numpy as np
import sys
import traceback
from wx.lib.agw import floatspin # Float numbers in spin fields
import wx


Expand Down Expand Up @@ -86,7 +83,7 @@ def save_figure(self, evt=None):
Page = self.canvas.HACK_Page
add = self.canvas.HACK_append
dirname = parent.dirname
filename = Page.tabtitle.GetValue().strip()+Page.counter[:2]+add
filename = self.canvas.get_window_title().replace(" ", "_").lower()+add
formats = fig.canvas.get_supported_filetypes()
except:
dirname = "."
Expand All @@ -108,12 +105,8 @@ def save_figure(self, evt=None):
if dlg.ShowModal() == wx.ID_OK:
wildcard = keys[dlg.GetFilterIndex()]
filename = dlg.GetPath()
haswc = False
for key in keys:
if filename.lower().endswith("."+key) is True:
haswc = True
if haswc == False:
filename = filename+"."+wildcard
if not filename.endswith(wildcard):
filename += "."+wildcard
dirname = dlg.GetDirectory()
#savename = os.path.join(dirname, filename)
savename = filename
Expand Down
6 changes: 3 additions & 3 deletions pycorrfit/frontend.py
Expand Up @@ -1454,8 +1454,8 @@ def OnSaveData(self,e=None):
# Export CSV data
filename = Page.tabtitle.GetValue().strip()+Page.counter[:2]+".csv"
dlg = wx.FileDialog(self, "Save curve", self.dirname, filename,
"Correlation with trace (*.csv)|*.csv;*.CSV"+\
"|Correlation only (*.csv)|*.csv;*.CSV",
"Correlation with trace (*.csv)|*.csv;*.*"+\
"|Correlation only (*.csv)|*.csv;*.*",
wx.FD_SAVE|wx.FD_OVERWRITE_PROMPT)
# user cannot do anything until he clicks "OK"
if dlg.ShowModal() == wx.ID_OK:
Expand Down Expand Up @@ -1594,7 +1594,7 @@ def OnSaveSession(self,e=None):
Infodict["Comments"]["Session"] = self.SessionComment
# File dialog
dlg = wx.FileDialog(self, "Save session file", self.dirname, "",
"PyCorrFit session (*.pcfs)|*.pcfs",
"PyCorrFit session (*.pcfs)|*.pcfs|All files (*.*)|*.*",
wx.FD_SAVE|wx.FD_OVERWRITE_PROMPT)
if dlg.ShowModal() == wx.ID_OK:
# Save everything
Expand Down
65 changes: 2 additions & 63 deletions pycorrfit/plotting.py
Expand Up @@ -281,7 +281,7 @@ def savePlotCorrelation(parent, dirname, Page, uselatex=False,
fig.canvas.HACK_parent = parent
fig.canvas.HACK_fig = fig
fig.canvas.HACK_Page = Page
fig.canvas.HACK_append = ""
fig.canvas.HACK_append = ".png"


# Legend outside of plot
Expand Down Expand Up @@ -402,7 +402,7 @@ def savePlotTrace(parent, dirname, Page, uselatex=False, verbose=False):
fig.canvas.HACK_parent = parent
fig.canvas.HACK_fig = fig
fig.canvas.HACK_Page = Page
fig.canvas.HACK_append = "_trace"
fig.canvas.HACK_append = "_trace.png"

plt.tight_layout(rect=(.001,.34,.999,1.0))

Expand All @@ -421,66 +421,5 @@ def savePlotTrace(parent, dirname, Page, uselatex=False, verbose=False):
except:
pass


def savePlotSingle(name, x, dataexp, datafit, dirname = ".", uselatex=False):
""" CURRENTLY THIS FUNCTION IS NOT USED BY PYCORRFIT
Show log plot of correlation function without residuals.
Parameters:
*name* name of curve in legend
*x* tau-values to plot
*dataexp* correlation data to plot
*datafit* fitted curve to correlation data
*dirname* initial directory for dialog (not used here)
*uselatex* use latex for plotting
This function uses a hack in misc.py to change the function
for saving the final figure. We wanted save in the same directory
as PyCorrFit was working and the filename should be the tabtitle.
"""
# This is a dirty hack to make sure no plots are opened
try:
plt.close()
except:
pass
## Check if we can use latex for plotting:
r1 = findprogram("latex")[0]
r2 = findprogram("dvipng")[0]
# Ghostscript
r31 = findprogram("gs")[0]
r32 = findprogram("mgs")[0] # from miktex
r3 = max(r31,r32)
if r1+r2+r3 < 3:
uselatex = False
if uselatex == True:
rcParams['text.usetex']=True
rcParams['text.latex.unicode']=True
rcParams['font.family']='serif'
rcParams['text.latex.preamble']=[r"\usepackage{amsmath}"]
name = ur"{\normalsize "+escapechars(name)+r"}"
else:
rcParams['text.usetex']=False
# create plot
# plt.plot(x, y, '.', label = 'original data', markersize=5)
plt.figure()
ax = plt.subplot(111)
# ax = plt.axes()
ax.semilogx()
plt.plot(x, dataexp,'-', color="darkgrey")
plt.xlabel(r'lag time $\tau$ [ms]')
plt.plot(x, datafit, '-', label = name,
lw=2.5, color="blue")
plt.ylabel('correlation')
mind = np.min([ dataexp, datafit])
maxd = np.max([ dataexp, datafit])
ymin = mind - (maxd - mind)/20.
ymax = maxd + (maxd - mind)/20.
ax.set_ylim(bottom=ymin, top=ymax)
xmin = np.min(x)
xmax = np.max(x)
ax.set_xlim(xmin, xmax)
# Add some more stuff to the text and append data to a .txt file
#text = Auswert(parmname, parmoptim, text, savename)
plt.legend()
plt.show()

# set dpi to 300
matplotlib.rcParams['savefig.dpi'] = 300

0 comments on commit 08618d8

Please sign in to comment.