Skip to content

Commit

Permalink
[processing] update polar plot
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbruy committed Feb 15, 2017
1 parent 19289cc commit b3ab554
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 34 deletions.
26 changes: 8 additions & 18 deletions python/plugins/processing/algs/qgis/PolarPlot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)
21 changes: 5 additions & 16 deletions python/plugins/processing/algs/qgis/QGISAlgorithmProvider.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit b3ab554

Please sign in to comment.