Skip to content

Commit

Permalink
[processing] update vector layer histogram
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbruy committed Feb 15, 2017
1 parent a352773 commit e0131a7
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
6 changes: 4 additions & 2 deletions python/plugins/processing/algs/qgis/QGISAlgorithmProvider.py
Expand Up @@ -276,14 +276,16 @@ def __init__(self):
#~ 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

Expand Down
14 changes: 6 additions & 8 deletions python/plugins/processing/algs/qgis/VectorLayerHistogram.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 Down Expand Up @@ -66,9 +66,7 @@ def processAlgorithm(self, feedback):
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)
Expand Up @@ -72,6 +72,5 @@ def processAlgorithm(self, feedback):
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)

0 comments on commit e0131a7

Please sign in to comment.