25
25
26
26
__revision__ = '$Format:%H$'
27
27
28
- import matplotlib . pyplot as plt
29
- import matplotlib . pylab as lab
28
+ import plotly as plt
29
+ import plotly . graph_objs as go
30
30
31
31
from processing .core .GeoAlgorithm import GeoAlgorithm
32
32
from processing .core .parameters import ParameterVector
@@ -51,10 +51,12 @@ def defineCharacteristics(self):
51
51
self .addParameter (ParameterVector (self .INPUT ,
52
52
self .tr ('Input layer' )))
53
53
self .addParameter (ParameterTableField (self .XFIELD ,
54
- self .tr ('X attribute' ), self .INPUT ,
54
+ self .tr ('X attribute' ),
55
+ self .INPUT ,
55
56
ParameterTableField .DATA_TYPE_NUMBER ))
56
57
self .addParameter (ParameterTableField (self .YFIELD ,
57
- self .tr ('Y attribute' ), self .INPUT ,
58
+ self .tr ('Y attribute' ),
59
+ self .INPUT ,
58
60
ParameterTableField .DATA_TYPE_NUMBER ))
59
61
60
62
self .addOutput (OutputHTML (self .OUTPUT , self .tr ('Scatterplot' )))
@@ -68,11 +70,8 @@ def processAlgorithm(self, feedback):
68
70
output = self .getOutputValue (self .OUTPUT )
69
71
70
72
values = vector .values (layer , xfieldname , yfieldname )
71
- plt .close ()
72
- plt .scatter (values [xfieldname ], values [yfieldname ])
73
- plt .ylabel (yfieldname )
74
- plt .xlabel (xfieldname )
75
- plotFilename = output + '.png'
76
- lab .savefig (plotFilename )
77
- with open (output , 'w' ) as f :
78
- f .write ('<html><img src="' + plotFilename + '"/></html>' )
73
+ data = [go .Scatter (x = values [xfieldname ],
74
+ y = values [yfieldname ],
75
+ mode = 'markers'
76
+ )]
77
+ plt .offline .plot (data , filename = output )
0 commit comments