Skip to content
Permalink
Browse files

[processing] update vector layer scatterplot

  • Loading branch information
alexbruy committed Feb 15, 2017
1 parent 46a9891 commit a352773887419a172adecc845d7e4f8701bd2ba7
@@ -278,12 +278,12 @@ def __init__(self):
if hasPlotly:
#~ from .VectorLayerHistogram import VectorLayerHistogram
#~ from .RasterLayerHistogram import RasterLayerHistogram
#~ from .VectorLayerScatterplot import VectorLayerScatterplot
from .VectorLayerScatterplot import VectorLayerScatterplot
#~ from .MeanAndStdDevPlot import MeanAndStdDevPlot
from .BarPlot import BarPlot
#~ from .PolarPlot import PolarPlot

self.alglist.extend([BarPlot()])
self.alglist.extend([VectorLayerScatterplot(), BarPlot()])

self.externalAlgs = [] # to store algs added by 3rd party plugins as scripts

@@ -25,8 +25,8 @@

__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
@@ -51,10 +51,12 @@ def defineCharacteristics(self):
self.addParameter(ParameterVector(self.INPUT,
self.tr('Input layer')))
self.addParameter(ParameterTableField(self.XFIELD,
self.tr('X attribute'), self.INPUT,
self.tr('X attribute'),
self.INPUT,
ParameterTableField.DATA_TYPE_NUMBER))
self.addParameter(ParameterTableField(self.YFIELD,
self.tr('Y attribute'), self.INPUT,
self.tr('Y attribute'),
self.INPUT,
ParameterTableField.DATA_TYPE_NUMBER))

self.addOutput(OutputHTML(self.OUTPUT, self.tr('Scatterplot')))
@@ -68,11 +70,8 @@ def processAlgorithm(self, feedback):
output = self.getOutputValue(self.OUTPUT)

values = vector.values(layer, xfieldname, yfieldname)
plt.close()
plt.scatter(values[xfieldname], values[yfieldname])
plt.ylabel(yfieldname)
plt.xlabel(xfieldname)
plotFilename = output + '.png'
lab.savefig(plotFilename)
with open(output, 'w') as f:
f.write('<html><img src="' + plotFilename + '"/></html>')
data = [go.Scatter(x=values[xfieldname],
y=values[yfieldname],
mode='markers'
)]
plt.offline.plot(data, filename=output)

0 comments on commit a352773

Please sign in to comment.
You can’t perform that action at this time.