Skip to content
Permalink
Browse files

[processing] update polar plot

  • Loading branch information
alexbruy committed Feb 15, 2017
1 parent 19289cc commit b3ab5543dd107a54a262dff6757b6e058c6c71e3
@@ -25,17 +25,15 @@

__revision__ = '$Format:%H$'

import matplotlib.pyplot as plt
import matplotlib.pylab as lab
from matplotlib.pyplot import figure
import plotly as plt
import plotly.graph_objs as go
import numpy as np

from processing.core.GeoAlgorithm import GeoAlgorithm
from processing.core.parameters import ParameterTable
from processing.core.parameters import ParameterTableField
from processing.core.outputs import OutputHTML
from processing.tools import vector
from processing.tools import dataobjects
from processing.tools import dataobjects, vector


class PolarPlot(GeoAlgorithm):
@@ -66,16 +64,8 @@ def processAlgorithm(self, feedback):

output = self.getOutputValue(self.OUTPUT)

values = vector.values(layer, namefieldname, valuefieldname)
plt.close()
fig = figure(figsize=(8, 8))
ax = fig.add_axes([0.1, 0.1, 0.8, 0.8], polar=True)
N = len(values[valuefieldname])
theta = np.arange(0.0, 2 * np.pi, 2 * np.pi / N)
radii = values[valuefieldname]
width = 2 * np.pi / N
ax.bar(theta, radii, width=width, bottom=0.0)
plotFilename = output + '.png'
lab.savefig(plotFilename)
with open(output, 'w') as f:
f.write('<html><img src="' + plotFilename + '"/></html>')
values = vector.values(layer, valuefieldname)

data = [go.Area(r=values[valuefieldname],
t=np.degrees(np.arange(0.0, 2 * np.pi, 2 * np.pi / len(values[valuefieldname]))))]
plt.offline.plot(data, filename=output)
@@ -262,31 +262,20 @@ def __init__(self):
FixGeometry(), ExecuteSQL(), FindProjection()
]

#~ if hasMatplotlib:
#~ 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([
#~ VectorLayerHistogram(), RasterLayerHistogram(),
#~ VectorLayerScatterplot(), MeanAndStdDevPlot(), BarPlot(),
#~ PolarPlot(),
#~ ])
if hasPlotly:
from .VectorLayerHistogram import VectorLayerHistogram
from .RasterLayerHistogram import RasterLayerHistogram
from .VectorLayerScatterplot import VectorLayerScatterplot
from .MeanAndStdDevPlot import MeanAndStdDevPlot
from .BarPlot import BarPlot
#~ from .PolarPlot import PolarPlot
from .PolarPlot import PolarPlot

self.alglist.extend([VectorLayerHistogram(), RasterLayerHistogram(),
VectorLayerScatterplot(), MeanAndStdDevPlot(), BarPlot()])
VectorLayerScatterplot(), MeanAndStdDevPlot(),
BarPlot(), PolarPlot()])

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

folder = os.path.join(os.path.dirname(__file__), 'scripts')
scripts = ScriptUtils.loadFromFolder(folder)

0 comments on commit b3ab554

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