mirror of
https://github.com/qgis/QGIS.git
synced 2025-12-15 00:07:25 -05:00
[processing] update vector layer scatterplot
This commit is contained in:
parent
46a9891e5c
commit
a352773887
@ -278,12 +278,12 @@ class QGISAlgorithmProvider(AlgorithmProvider):
|
||||
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 @@ __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
|
||||
@ -51,10 +51,12 @@ class VectorLayerScatterplot(GeoAlgorithm):
|
||||
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 @@ class VectorLayerScatterplot(GeoAlgorithm):
|
||||
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)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user