Commit 9aed6246 by devttys0

In process of replacing pymatplotlib with pyqtgraph.

parent a122a09a
...@@ -458,8 +458,8 @@ def main(): ...@@ -458,8 +458,8 @@ def main():
pass pass
except IOError: except IOError:
pass pass
except Exception as e: # except Exception as e:
print("Unexpected error: %s" % str(e)) # print("Unexpected error: %s" % str(e))
bwalk.cleanup() bwalk.cleanup()
......
...@@ -11,15 +11,10 @@ class PlotEntropy(object): ...@@ -11,15 +11,10 @@ class PlotEntropy(object):
Class to plot entropy data on a graph. Class to plot entropy data on a graph.
''' '''
YLIM_MIN = 0
YLIM_MAX = 1.5
XLABEL = 'Offset' XLABEL = 'Offset'
YLABEL = 'Entropy' YLABEL = 'Entropy'
LINE_WIDTH = 1.5 COLORS = ['r', 'g', 'b', 'c', 'm', 'w']
COLORS = ['darkgreen', 'blueviolet', 'saddlebrown', 'deeppink', 'goldenrod', 'olive', 'black']
FILE_FORMAT = 'svg' FILE_FORMAT = 'svg'
...@@ -37,53 +32,50 @@ class PlotEntropy(object): ...@@ -37,53 +32,50 @@ class PlotEntropy(object):
Returns None. Returns None.
''' '''
import matplotlib.pyplot as plt
import numpy as np import numpy as np
import pyqtgraph as pg
from pyqtgraph.Qt import QtCore, QtGui
i = 0 i = 0
trigger = 0 descriptions = {}
new_ticks = [] max_description_length = None
color_mappings = {}
plt.clf()
if file_results:
for (offset, results) in file_results: for (offset, results) in file_results:
label = None
description = results[0]['description'].split(',')[0] description = results[0]['description'].split(',')[0]
desc_len = len(description)
if not has_key(color_mappings, description): if not max_description_length or desc_len > max_description_length:
if show_legend: max_description_length = desc_len
label = description
color_mappings[description] = self.COLORS[i]
i += 1
if i >= len(self.COLORS):
i = 0
plt.axvline(x=offset, label=label, color=color_mappings[description], linewidth=self.LINE_WIDTH) if has_key(descriptions, offset):
new_ticks.append(offset) descriptions[offset].append(description)
else:
descriptions[offset] = [description]
if show_legend:
plt.legend()
if new_ticks: plt = pg.plot(title=title, clear=True)
new_ticks.sort() plt.plot(x, y, pen='y')
plt.xticks(np.array(new_ticks), new_ticks) if file_results and show_legend:
plt.addLegend(size=(max_description_length*10, 0))
plt.plot(x, y, linewidth=self.LINE_WIDTH) #if average:
# plt.addLine(y=average, pen='r')
if average: if file_results:
plt.plot(x, [average] * len(x), linestyle='--', color='r') for (offset, descs) in iterator(descriptions):
for description in descs:
plt.plot(x=[offset,offset], y=[0,1.1], name=description, pen=pg.mkPen(self.COLORS[i], width=2.5))
i += 1
if i >= len(self.COLORS):
i = 0
plt.xlabel(self.XLABEL)
plt.ylabel(self.YLABEL)
plt.title(title)
plt.ylim(self.YLIM_MIN, self.YLIM_MAX)
if save: if save:
plt.savefig(common.unique_file_name(title, self.FILE_FORMAT)) # TODO
pass
#plt.savefig(common.unique_file_name(title, self.FILE_FORMAT))
else: else:
plt.show() plt.setWindowTitle(title)
QtGui.QApplication.instance().exec_()
class FileEntropy(object): class FileEntropy(object):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment