Skip to content

Commit 2fa77a7

Browse files
parameters for export figure can now be controlled using export fig window popup, all functionality working for X-Y plot export for two traces
1 parent 4413533 commit 2fa77a7

File tree

2 files changed

+78
-16
lines changed

2 files changed

+78
-16
lines changed

PythonGUI_apps/Lifetime_analysis/Lifetime_plot_fit.py

+49-5
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def __init__(self):
6767
self.ui.plot_pushButton.clicked.connect(self.plot)
6868
self.ui.fit_pushButton.clicked.connect(self.call_fit_and_plot)
6969
self.ui.clear_pushButton.clicked.connect(self.clear_plot)
70-
self.ui.export_plot_pushButton.clicked.connect(self.pub_ready_plot_export)
70+
self.ui.export_plot_pushButton.clicked.connect(self.export_window)#pub_ready_plot_export
7171
self.ui.calculate_srv_pushButton.clicked.connect(self.calculate_srv)
7272

7373
self.ui.log_checkBox.stateChanged.connect(self.make_semilog)
@@ -518,6 +518,10 @@ def export_data(self):
518518

519519
def clear_export_data(self):
520520
self.data_list = []
521+
522+
def export_window(self):
523+
self.exportplotwindow = ExportPlotWindow()
524+
self.exportplotwindow.export_fig_signal.connect(self.pub_ready_plot_export)
521525

522526
def pub_ready_plot_export(self):
523527
try:
@@ -526,19 +530,27 @@ def pub_ready_plot_export(self):
526530
plt.figure(figsize=(8,6))
527531
plt.tick_params(direction='out', length=8, width=3.5)
528532
if self.ui.save_w_fit_checkBox.isChecked():
529-
plt.plot(self.out[:,0],self.out[:,1]/np.max(self.out[:,1]))
530-
plt.plot(self.out[:,0],self.out[:,2]/np.max(self.out[:,1]),'k')
533+
plt.plot(self.out[:,0],self.out[:,1]/np.max(self.out[:,1]),self.exportplotwindow.ui.traceColor_comboBox.currentText())
534+
plt.plot(self.out[:,0],self.out[:,2]/np.max(self.out[:,1]),self.exportplotwindow.ui.fitColor_comboBox.currentText())
535+
if self.exportplotwindow.ui.legend_checkBox.isChecked():
536+
plt.legend([self.exportplotwindow.ui.legend1_lineEdit.text(),self.exportplotwindow.ui.legend2_lineEdit.text()])
531537
else:
532-
plt.plot(self.acquire_settings()[0],self.acquire_settings()[1]/np.max(self.acquire_settings()[1]))
538+
plt.plot(self.acquire_settings()[0],self.acquire_settings()[1]/np.max(self.acquire_settings()[1]),
539+
self.exportplotwindow.ui.traceColor_comboBox.currentText())
540+
if self.exportplotwindow.ui.legend_checkBox.isChecked():
541+
plt.legend([self.exportplotwindow.ui.legend1_lineEdit.text()])
533542
plt.yscale('log')
534543
plt.xlabel("Time (ns)", fontsize=20, fontweight='bold')
535544
plt.ylabel("Intensity (norm.)", fontsize=20, fontweight='bold')
536545
plt.tight_layout()
546+
plt.xlim([self.exportplotwindow.ui.lowerX_spinBox.value(),self.exportplotwindow.ui.upperX_spinBox.value()])
547+
plt.ylim([10**(self.exportplotwindow.ui.lowerY_spinBox.value()),self.exportplotwindow.ui.upperY_doubleSpinBox.value()])
537548

538549
plt.savefig(filename[0],bbox_inches='tight', dpi=300)
539550
plt.close()
540551

541-
except:
552+
except Exception as e:
553+
self.ui.Result_textBrowser.append(format(e))
542554
pass
543555

544556
def close_application(self):
@@ -572,6 +584,38 @@ def done(self):
572584
self.skip_rows_signal.emit()
573585
self.close()
574586

587+
"""Export plot GUI"""
588+
ui_file_path = (base_path / "export_plot.ui").resolve()
589+
export_WindowTemplate, export_TemplateBaseClass = pg.Qt.loadUiType(ui_file_path)
590+
591+
class ExportPlotWindow(export_TemplateBaseClass):
592+
593+
export_fig_signal = QtCore.pyqtSignal()
594+
595+
def __init__(self):
596+
export_TemplateBaseClass.__init__(self)
597+
598+
self.ui = export_WindowTemplate()
599+
self.ui.setupUi(self)
600+
self.ui.traceColor_comboBox.addItems(["C0","C1","C2","C3","C4","C5","C6","C7", "r", "g", "b", "y", "k"])
601+
self.ui.fitColor_comboBox.addItems(["k", "r", "b", "y", "g","C0","C1","C2","C3","C4","C5","C6","C7"])
602+
self.ui.export_pushButton.clicked.connect(self.export)
603+
self.ui.legend_checkBox.stateChanged.connect(self.legend_title)
604+
self.show()
605+
606+
def legend_title(self):
607+
if self.ui.legend_checkBox.isChecked():
608+
self.ui.legend1_lineEdit.setEnabled(True)
609+
self.ui.legend2_lineEdit.setEnabled(True)
610+
else:
611+
self.ui.legend1_lineEdit.setEnabled(False)
612+
self.ui.legend2_lineEdit.setEnabled(False)
613+
614+
def export(self):
615+
self.export_fig_signal.emit()
616+
self.close()
617+
618+
575619
def run():
576620
win = MainWindow()
577621
QtGui.QApplication.instance().exec_()

PythonGUI_apps/Lifetime_analysis/export_plot.ui

+29-11
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
<rect>
77
<x>0</x>
88
<y>0</y>
9-
<width>573</width>
10-
<height>322</height>
9+
<width>714</width>
10+
<height>435</height>
1111
</rect>
1212
</property>
1313
<property name="windowTitle">
@@ -167,7 +167,19 @@
167167
</property>
168168
</widget>
169169
</item>
170-
<item row="3" column="3">
170+
<item row="5" column="0" colspan="5">
171+
<widget class="QPushButton" name="export_pushButton">
172+
<property name="font">
173+
<font>
174+
<pointsize>17</pointsize>
175+
</font>
176+
</property>
177+
<property name="text">
178+
<string>Export Graph</string>
179+
</property>
180+
</widget>
181+
</item>
182+
<item row="4" column="3">
171183
<widget class="QLabel" name="label_11">
172184
<property name="font">
173185
<font>
@@ -179,8 +191,11 @@
179191
</property>
180192
</widget>
181193
</item>
182-
<item row="3" column="2">
194+
<item row="4" column="2">
183195
<widget class="QLineEdit" name="legend1_lineEdit">
196+
<property name="enabled">
197+
<bool>false</bool>
198+
</property>
184199
<property name="font">
185200
<font>
186201
<pointsize>12</pointsize>
@@ -218,16 +233,19 @@
218233
</property>
219234
</widget>
220235
</item>
221-
<item row="3" column="4">
236+
<item row="4" column="4">
222237
<widget class="QLineEdit" name="legend2_lineEdit">
238+
<property name="enabled">
239+
<bool>false</bool>
240+
</property>
223241
<property name="font">
224242
<font>
225243
<pointsize>12</pointsize>
226244
</font>
227245
</property>
228246
</widget>
229247
</item>
230-
<item row="3" column="0">
248+
<item row="4" column="0">
231249
<widget class="QLabel" name="label_12">
232250
<property name="font">
233251
<font>
@@ -239,7 +257,7 @@
239257
</property>
240258
</widget>
241259
</item>
242-
<item row="3" column="1">
260+
<item row="4" column="1">
243261
<widget class="QLabel" name="label_10">
244262
<property name="font">
245263
<font>
@@ -251,15 +269,15 @@
251269
</property>
252270
</widget>
253271
</item>
254-
<item row="4" column="0" colspan="5">
255-
<widget class="QPushButton" name="pushButton">
272+
<item row="3" column="0" colspan="2">
273+
<widget class="QCheckBox" name="legend_checkBox">
256274
<property name="font">
257275
<font>
258-
<pointsize>17</pointsize>
276+
<pointsize>15</pointsize>
259277
</font>
260278
</property>
261279
<property name="text">
262-
<string>Export Graph</string>
280+
<string>Add Legends to the Plot</string>
263281
</property>
264282
</widget>
265283
</item>

0 commit comments

Comments
 (0)