1
0
Fork 0
mirror of https://github.com/Athemis/PyDSF.git synced 2025-04-04 22:36:02 +00:00

Start reimplementing plotting code

This commit is contained in:
Alexander Minges 2015-02-10 03:19:40 +01:00
parent 9d1e3d8fa2
commit fef87a6657
5 changed files with 152 additions and 54 deletions

View file

@ -1,14 +1,18 @@
#! /usr/bin/env python2
# -*- coding: utf-8 -*-
import csv
import random
try:
import matplotlib as mpl
#import mpl_toolkits.axes_grid
import mpl_toolkits.axes_grid1
mpl.use('Qt5Agg')
mpl.interactive(True)
import matplotlib.ticker as ticker
import matplotlib.pyplot as plt
import matplotlib.patches as mpatches
import matplotlib.gridspec as gridspec
except ImportError:
raise ImportError('----- Matplotlib must be installed. -----')
@ -436,9 +440,6 @@ def update_progress_bar(bar, value):
class PlotResults():
def __init__(self, experiment):
self.experiment = experiment
def plot_tm_heatmap_single(self, plate, widget):
"""
Plot Tm heatmap (Fig. 1)
@ -550,35 +551,86 @@ class PlotResults():
"""
canvas = widget.canvas
canvas.clear()
fig3 = canvas.fig # new figure
fig3.suptitle('Raw Data (plate #{})'.format(str(plate.id))) # set title
for plot_num in range(1, plate.wellnum + 1): # iterate over all wells
well = plate.wells[plot_num - 1] # get single well based on current plot number
ax = fig3.add_subplot(plate.rows, plate.cols, plot_num) # add new subplot
ax.autoscale(tight=True) # scale to data
ax.set_title(well.name, size='xx-small') # set title of current subplot to well identifier
im = np.arange(100)
im.shape = 10, 10
if well in plate.denatured_wells:
ax.patch.set_facecolor('#FFD6D6')
if plot_num == plate.wellnum - plate.cols + 1: # add axis label to the subplot in the bottom left corner of the figure
ax.set_xlabel(u'T [°C]', size='xx-small')
ax.set_ylabel('I', size='xx-small')
fig = canvas.fig
fig.suptitle('Raw Data (plate #{})'.format(str(plate.id)))
grid = mpl_toolkits.axes_grid1.Grid(fig, 111, nrows_ncols=(plate.rows, plate.cols), axes_pad=(0.1, 0.25), add_all=True, share_x=True, share_y=True, share_all=True)
for i in range(plate.wellnum):
well = plate.wells[i]
x = plate.temprange # set values for the x axis to the given temperature range
y = well.raw # grab y values from the raw data of the well
ax = grid[i]
#ax = fig.add_subplot(plate.rows, plate.cols, i+1)
ax.set_title(well.name, size=6) # set title of current subplot to well identifier
if well in plate.denatured_wells:
ax.patch.set_facecolor('#FFD6D6')
ax.xaxis.set_major_locator(ticker.MaxNLocator(4)) # only show three tickmarks on both axes
ax.yaxis.set_major_locator(ticker.MaxNLocator(4))
ax.axvspan(plate.t1, plate.tm_cutoff_low, facecolor='0.8', alpha=0.5) # shade lower cutoff area
ax.axvspan(plate.tm_cutoff_high, plate.t2, facecolor='0.8', alpha=0.5) # shade higher cutoff area
for label in ax.get_xticklabels() + ax.get_yticklabels(): # set fontsize for all tick labels to xx-small
label.set_fontsize('xx-small')
cax = ax.plot(x, y) # plot data to the current subplot
label.set_fontsize(6)
ax.plot(x, y)
fig.tight_layout()
canvas.draw()
#ax = grid[i]
#ax.axhline(color='r')
#ax.autoscale(enable=True, axis='y', tight=True)
#ax.set_title(well.name, size='xx-small')
#ax.plot(x, 1000*np.random.random(76))
#ax.set_yscale('log')
#for plot_num in range(1, plate.wellnum + 1):
# well = plate.wells[plot_num - 1]
# #ax = fig.add_subplot(plate.rows, plate.cols, plot_num)
# ax.autoscale(tight=True)
# ax.plot(plate.temprange, well.raw)
# ax.set_title(well.name, size='xx-small')
# if well in plate.denatured_wells:
# ax.patch.set_facecolor('#FFD6D6')
#for plot_num in range(1, plate.wellnum + 1):
# ax = fig.add_subplot(plate.rows, plate.cols, plot_num)
# ax.autoscale(tight=True)
# fig3 = canvas.fig # new figure
# fig3.suptitle('Raw Data (plate #{})'.format(str(plate.id))) # set title
#
# for plot_num in range(1, plate.wellnum + 1): # iterate over all wells
# well = plate.wells[plot_num - 1] # get single well based on current plot number
# ax = fig3.add_subplot(plate.rows, plate.cols, plot_num) # add new subplot
# ax = fig3.add_axes(plate.rows, plate.cols, plot_num)
# ax.autoscale(tight=True) # scale to data
# ax.set_title(well.name, size='xx-small') # set title of current subplot to well identifier
#
# if well in plate.denatured_wells:
# ax.patch.set_facecolor('#FFD6D6')
#
# if plot_num == plate.wellnum - plate.cols + 1: # add axis label to the subplot in the bottom left corner of the figure
# ax.set_xlabel(u'T [°C]', size='xx-small')
# ax.set_ylabel('I', size='xx-small')
#
# x = plate.temprange # set values for the x axis to the given temperature range
# y = well.raw # grab y values from the raw data of the well
#
# ax.xaxis.set_major_locator(ticker.MaxNLocator(4)) # only show three tickmarks on both axes
# ax.yaxis.set_major_locator(ticker.MaxNLocator(4))
# ax.axvspan(plate.t1, plate.tm_cutoff_low, facecolor='0.8', alpha=0.5) # shade lower cutoff area
# ax.axvspan(plate.tm_cutoff_high, plate.t2, facecolor='0.8', alpha=0.5) # shade higher cutoff area
# for label in ax.get_xticklabels() + ax.get_yticklabels(): # set fontsize for all tick labels to xx-small
# label.set_fontsize('xx-small')
#
# cax = ax.plot(x, y) # plot data to the current subplot
# def _plot_wrapper(self, plot, plate):
#

View file

@ -202,19 +202,19 @@ class Ui_MainWindow(object):
self.tabWidget.setSizePolicy(sizePolicy)
self.tabWidget.setMinimumSize(QtCore.QSize(300, 300))
self.tabWidget.setObjectName("tabWidget")
self.tab_raw = MplWidget()
self.tab_raw.setObjectName("tab_raw")
self.tabWidget.addTab(self.tab_raw, "")
self.tab_derivative = MplWidget()
self.tab_derivative.setObjectName("tab_derivative")
self.tabWidget.addTab(self.tab_derivative, "")
self.tab_heatmap = MplWidget()
self.tab_heatmap.setObjectName("tab_heatmap")
self.tabWidget.addTab(self.tab_heatmap, "")
self.tab_heatmap_avg = MplWidget()
self.tab_heatmap_avg.setEnabled(False)
self.tab_heatmap_avg.setObjectName("tab_heatmap_avg")
self.tabWidget.addTab(self.tab_heatmap_avg, "")
#self.tab_raw = MplWidget()
#self.tab_raw.setObjectName("tab_raw")
#self.tabWidget.addTab(self.tab_raw, "")
#self.tab_derivative = MplWidget()
#self.tab_derivative.setObjectName("tab_derivative")
#self.tabWidget.addTab(self.tab_derivative, "")
#self.tab_heatmap = MplWidget()
#self.tab_heatmap.setObjectName("tab_heatmap")
#self.tabWidget.addTab(self.tab_heatmap, "")
#self.tab_heatmap_avg = MplWidget()
#self.tab_heatmap_avg.setEnabled(False)
#self.tab_heatmap_avg.setObjectName("tab_heatmap_avg")
#self.tabWidget.addTab(self.tab_heatmap_avg, "")
self.horizontalLayout.addWidget(self.splitter)
MainWindow.setCentralWidget(self.centralWidget)
self.menuBar = QtWidgets.QMenuBar(MainWindow)
@ -291,10 +291,10 @@ class Ui_MainWindow(object):
self.doubleSpinBox_cbar_start.setSuffix(_translate("MainWindow", " °C"))
self.label_cbar_end.setText(_translate("MainWindow", "En&d"))
self.doubleSpinBox_cbar_end.setSuffix(_translate("MainWindow", " °C"))
self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab_raw), _translate("MainWindow", "Raw Data"))
self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab_derivative), _translate("MainWindow", "&1st derivative"))
self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab_heatmap), _translate("MainWindow", "Heatmap"))
self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab_heatmap_avg), _translate("MainWindow", "Heatmap average"))
#self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab_raw), _translate("MainWindow", "Raw Data"))
#self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab_derivative), _translate("MainWindow", "&2nd derivative"))
#self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab_heatmap), _translate("MainWindow", "Heatmap"))
#self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab_heatmap_avg), _translate("MainWindow", "Heatmap average"))
self.menuFile.setTitle(_translate("MainWindow", "Fi&le"))
self.menuHelp.setTitle(_translate("MainWindow", "Hel&p"))
self.actionQuit.setText(_translate("MainWindow", "&Quit"))

View file

@ -6,12 +6,20 @@ Module implementing MainWindow.
VERSION = "1.0"
from PyQt5.QtCore import pyqtSlot
from PyQt5.QtCore import pyqtSlot, QObject, pyqtSignal
from PyQt5.QtWidgets import *
from .Ui_mainwindow import Ui_MainWindow
from .mplwidget import MplWidget
from pydsf import *
class ProcessData(QObject):
finished = pyqtSignal()
def process(self):
raise NotImplementedError
class MainWindow(QMainWindow, Ui_MainWindow):
"""
@ -70,6 +78,27 @@ class MainWindow(QMainWindow, Ui_MainWindow):
# self.groupBox_cbar.setEnabled(True)
# self.groupBox_signal_threshold.setEnabled(True)
def generate_plot_tab(self, name):
tab = MplWidget()
tab.setObjectName(name)
return tab
def generate_plate_tabs(self, plate):
plotter = PlotResults()
if id != 'average':
tab = self.generate_plot_tab("tab_heatmap_{}".format(id))
self.tabWidget.addTab(tab, "Heatmap #{}".format(plate.id))
plotter.plot_tm_heatmap_single(plate, tab)
tab = self.generate_plot_tab("tab_raw_{}".format(id))
self.tabWidget.addTab(tab, "Raw Data #{}".format(plate.id))
plotter.plot_raw(plate, tab)
else:
tab = self.generate_plot_tab("tab_heatmap_{}".format(id))
self.tabWidget.addTab(tab, "Heatmap ({})".format(plate.id))
plotter.plot_tm_heatmap_single(plate, tab)
@pyqtSlot()
def on_buttonBox_process_accepted(self):
"""
@ -128,20 +157,36 @@ class MainWindow(QMainWindow, Ui_MainWindow):
exp.avg_plate.write_avg_tm_table('{}/plate_{}_05_tm_avg.csv'.format(folder, str(exp.avg_plate.id)))
#plot(plate, self)
plotter = PlotResults(exp)
for i in range(self.tabWidget.count()):
for plate in exp.plates:
if i == 0:
plotter.plot_raw(plate, self.tabWidget.widget(i))
elif i == 1:
plotter.plot_derivative(plate, self.tabWidget.widget(i))
elif i == 2:
plotter.plot_tm_heatmap_single(plate, self.tabWidget.widget(i))
elif exp.avg_plate and i == 3:
plotter.plot_tm_heatmap_single(exp.avg_plate, self.tabWidget.widget(i))
self.tabWidget.setTabEnabled(i, True)
else:
self.tabWidget.setTabEnabled(i, False)
for i in range(len(exp.plates)):
plate = exp.plates[i]
self.generate_plate_tabs(plate)
if exp.avg_plate:
plate = exp.avg_plate
self.generate_plate_tabs(plate)
#for i in range(self.tabWidget.count()):
# for plate in exp.plates:
# if i == 0:
# plotter.plot_raw(plate, self.tabWidget.widget(i))
# self.tabWidget.setTabText(i, "Raw Data #{}".format(plate.id))
#elif i == 1:
# plotter.plot_derivative(plate, self.tabWidget.widget(i))
#elif i == 2:
# plotter.plot_tm_heatmap_single(plate, self.tabWidget.widget(i))
#elif exp.avg_plate and i == 3:
# plotter.plot_tm_heatmap_single(exp.avg_plate, self.tabWidget.widget(i))
# self.tabWidget.setTabEnabled(i, True)
#else:
# self.tabWidget.setTabEnabled(i, False)
#fig, ax = figures[0]
#self.tabWidget.widget(0).canvas.fig = fig
@ -190,3 +235,4 @@ class MainWindow(QMainWindow, Ui_MainWindow):
Slot documentation goes here.
"""
QApplication.aboutQt()

View file

@ -485,7 +485,7 @@
</widget>
<widget class="MplWidget" name="tab_derivative">
<attribute name="title">
<string>&amp;1st derivative</string>
<string>&amp;2nd derivative</string>
</attribute>
</widget>
<widget class="MplWidget" name="tab_heatmap">

View file

@ -10,6 +10,7 @@ class MplCanvas(FigureCanvas):
FigureCanvas.__init__(self, self.fig)
FigureCanvas.setSizePolicy(self, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding)
FigureCanvas.updateGeometry(self)
self.setFocusPolicy(QtCore.Qt.StrongFocus)
def clear(self):
self.ax.clear()
@ -18,7 +19,6 @@ class MplCanvas(FigureCanvas):
class MplWidget(QtWidgets.QWidget):
def __init__(self, parent = None):
QtWidgets.QWidget.__init__(self, parent)
self.canvas = MplCanvas()
self.ntb = NavigationToolbar(self.canvas, self)
self.vbl = QtWidgets.QVBoxLayout()