From e0131a75263cb7e2b72e959f6c1d6073befb6413 Mon Sep 17 00:00:00 2001 From: Alexander Bruy Date: Fri, 10 Feb 2017 14:30:32 +0200 Subject: [PATCH] [processing] update vector layer histogram --- .../processing/algs/qgis/QGISAlgorithmProvider.py | 6 ++++-- .../processing/algs/qgis/VectorLayerHistogram.py | 14 ++++++-------- .../processing/algs/qgis/VectorLayerScatterplot.py | 3 +-- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/python/plugins/processing/algs/qgis/QGISAlgorithmProvider.py b/python/plugins/processing/algs/qgis/QGISAlgorithmProvider.py index 64e3b41fa9c..010eb3f65d6 100644 --- a/python/plugins/processing/algs/qgis/QGISAlgorithmProvider.py +++ b/python/plugins/processing/algs/qgis/QGISAlgorithmProvider.py @@ -276,14 +276,16 @@ class QGISAlgorithmProvider(AlgorithmProvider): #~ PolarPlot(), #~ ]) if hasPlotly: - #~ from .VectorLayerHistogram import VectorLayerHistogram + from .VectorLayerHistogram import VectorLayerHistogram #~ from .RasterLayerHistogram import RasterLayerHistogram from .VectorLayerScatterplot import VectorLayerScatterplot #~ from .MeanAndStdDevPlot import MeanAndStdDevPlot from .BarPlot import BarPlot #~ from .PolarPlot import PolarPlot - self.alglist.extend([VectorLayerScatterplot(), BarPlot()]) + self.alglist.extend([ + VectorLayerHistogram(), VectorLayerScatterplot(), + BarPlot()]) self.externalAlgs = [] # to store algs added by 3rd party plugins as scripts diff --git a/python/plugins/processing/algs/qgis/VectorLayerHistogram.py b/python/plugins/processing/algs/qgis/VectorLayerHistogram.py index 5139e1a435d..371e829a329 100644 --- a/python/plugins/processing/algs/qgis/VectorLayerHistogram.py +++ b/python/plugins/processing/algs/qgis/VectorLayerHistogram.py @@ -25,8 +25,8 @@ __copyright__ = '(C) 2013, Victor Olaya' __revision__ = '$Format:%H$' -import matplotlib.pyplot as plt -import matplotlib.pylab as lab +import plotly as plt +import plotly.graph_objs as go from processing.core.GeoAlgorithm import GeoAlgorithm from processing.core.parameters import ParameterVector @@ -66,9 +66,7 @@ class VectorLayerHistogram(GeoAlgorithm): output = self.getOutputValue(self.OUTPUT) values = vector.values(layer, fieldname) - plt.close() - plt.hist(values[fieldname], bins) - plotFilename = output + '.png' - lab.savefig(plotFilename) - with open(output, 'w') as f: - f.write('') + + data = [go.Histogram(x=values[fieldname], + nbinsx=bins)] + plt.offline.plot(data, filename=output) diff --git a/python/plugins/processing/algs/qgis/VectorLayerScatterplot.py b/python/plugins/processing/algs/qgis/VectorLayerScatterplot.py index c9379714bb8..672cb6a2f48 100644 --- a/python/plugins/processing/algs/qgis/VectorLayerScatterplot.py +++ b/python/plugins/processing/algs/qgis/VectorLayerScatterplot.py @@ -72,6 +72,5 @@ class VectorLayerScatterplot(GeoAlgorithm): values = vector.values(layer, xfieldname, yfieldname) data = [go.Scatter(x=values[xfieldname], y=values[yfieldname], - mode='markers' - )] + mode='markers')] plt.offline.plot(data, filename=output)