[processing] update vector layer histogram

This commit is contained in:
Alexander Bruy 2017-02-10 14:30:32 +02:00
parent a352773887
commit e0131a7526
3 changed files with 11 additions and 12 deletions

View File

@ -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

View File

@ -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('<html><img src="' + plotFilename + '"/></html>')
data = [go.Histogram(x=values[fieldname],
nbinsx=bins)]
plt.offline.plot(data, filename=output)

View File

@ -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)