Skip to content

Commit 299e0da

Browse files
committed
Fix import for plots when GUI is used
1 parent 6575836 commit 299e0da

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

beams/gui.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from beams import in_out
88
from beams import grouping
99
from beams import annotation
10+
from beams import plots
1011
from PyQt5 import QtCore, QtGui, QtWidgets
1112
from beams.qt import form
1213
import sqlite3
@@ -489,6 +490,8 @@ def run(self):
489490

490491
separators = {"tab": "\t", "comma": ","}
491492
df_out.to_csv(self.lineEdit_summary_filename.text(), sep=separators[self.comboBox_separator.currentText()], index=False)
493+
plots.report(df=df_out, fn_pdf=os.path.join(os.path.dirname(self.lineEdit_summary_filename.text()), "report.pdf"),
494+
column_ppm_error="ppm_error", column_adducts="adduct")
492495
print("Done")
493496
print("")
494497

beams/plots.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,15 @@
55
import matplotlib
66

77
if platform != "win32":
8-
gui_env = ['TKAgg', 'GTKAgg', 'Qt4Agg', 'WXAgg']
8+
gui_env = ['Qt5Agg', 'TkAgg']
99
for gui in gui_env:
1010
try:
1111
matplotlib.use(gui, warn=False, force=True)
12-
from matplotlib import pyplot as plt
1312
break
1413
except:
1514
continue
16-
else:
17-
import matplotlib.pyplot as plt
1815

16+
import matplotlib.pyplot as plt
1917
from matplotlib import gridspec
2018
import seaborn as sns
2119

@@ -31,14 +29,16 @@ def report(df, column_ppm_error, column_adducts, fn_pdf):
3129
ax_count = plt.subplot(gs[3])
3230
#ax = plt.subplot(gs[1])
3331

34-
sns.boxplot(df[column_ppm_error], ax=ax_box)
35-
sns.distplot(df[column_ppm_error], ax=ax_hist)
32+
ppm_errors = df[column_ppm_error].dropna()
3633

37-
std = df[column_ppm_error].std()
38-
mean = df[column_ppm_error].mean()
39-
median = df[column_ppm_error].median()
40-
Q1 = df[column_ppm_error].quantile(0.25)
41-
Q3 = df[column_ppm_error].quantile(0.75)
34+
sns.boxplot(ppm_errors, ax=ax_box)
35+
sns.distplot(ppm_errors, ax=ax_hist)
36+
37+
std = ppm_errors.std()
38+
mean = ppm_errors.mean()
39+
median = ppm_errors.median()
40+
Q1 = ppm_errors.quantile(0.25)
41+
Q3 = ppm_errors.quantile(0.75)
4242

4343
# Remove x axis name for the boxplot
4444
ax_box.set(xlabel="")
@@ -49,11 +49,10 @@ def report(df, column_ppm_error, column_adducts, fn_pdf):
4949
ax_hist.set(xlabel="ppm error")
5050

5151
sns.set(style="whitegrid")
52-
sns.countplot(x=column_adducts, data=df, ax=ax_count)
52+
sns.countplot(df[column_adducts].dropna(), ax=ax_count)
5353

5454
plt.setp(ax_box.get_xticklabels(), visible=False)
5555

5656
fig.suptitle('Summary - BEAMS', fontsize=20)
5757
fig.set_size_inches(11.69, 8.27)
5858
fig.savefig(fn_pdf, format="pdf")
59-

0 commit comments

Comments
 (0)