Skip to content

Commit

Permalink
[processing] update vector layer scatterplot
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbruy committed Feb 15, 2017
1 parent 46a9891 commit a352773
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
4 changes: 2 additions & 2 deletions python/plugins/processing/algs/qgis/QGISAlgorithmProvider.py
Expand Up @@ -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

Expand Down
23 changes: 11 additions & 12 deletions python/plugins/processing/algs/qgis/VectorLayerScatterplot.py
Expand Up @@ -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
Expand All @@ -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')))
Expand All @@ -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.