Skip to content

Commit 46a9891

Browse files
committed
[processing] update bar plot
1 parent 34b277a commit 46a9891

File tree

2 files changed

+35
-25
lines changed

2 files changed

+35
-25
lines changed

python/plugins/processing/algs/qgis/BarPlot.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,11 @@
2525

2626
__revision__ = '$Format:%H$'
2727

28-
import matplotlib.pyplot as plt
29-
import matplotlib.pylab as lab
28+
#import matplotlib.pyplot as plt
29+
#import matplotlib.pylab as lab
30+
31+
import plotly as plt
32+
import plotly.graph_objs as go
3033
import numpy as np
3134

3235
from processing.core.parameters import ParameterTable
@@ -69,13 +72,8 @@ def processAlgorithm(self, feedback):
6972
output = self.getOutputValue(self.OUTPUT)
7073

7174
values = vector.values(layer, namefieldname, valuefieldname)
72-
plt.close()
7375

7476
ind = np.arange(len(values[namefieldname]))
75-
width = 0.8
76-
plt.bar(ind, values[valuefieldname], width, color='r')
77-
plt.xticks(ind, values[namefieldname], rotation=45)
78-
plotFilename = output + '.png'
79-
lab.savefig(plotFilename)
80-
with open(output, 'w') as f:
81-
f.write('<html><img src="' + plotFilename + '"/></html>')
77+
data = [go.Bar(x=ind,
78+
y=values[valuefieldname])]
79+
plt.offline.plot(data, filename=output)

python/plugins/processing/algs/qgis/QGISAlgorithmProvider.py

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,14 @@
2828
import os
2929

3030
try:
31-
import matplotlib.pyplot
32-
assert matplotlib # NOQA silence pyflakes
33-
hasMatplotlib = True
31+
#import matplotlib.pyplot
32+
#assert matplotlib # NOQA silence pyflakes
33+
#hasMatplotlib = True
34+
import plotly
35+
hasPlotly = True
3436
except:
35-
hasMatplotlib = False
37+
#hasMatplotlib = False
38+
hasPlotly = False
3639

3740
from qgis.PyQt.QtGui import QIcon
3841

@@ -259,19 +262,28 @@ def __init__(self):
259262
FixGeometry(), ExecuteSQL(), FindProjection()
260263
]
261264

262-
if hasMatplotlib:
263-
from .VectorLayerHistogram import VectorLayerHistogram
264-
from .RasterLayerHistogram import RasterLayerHistogram
265-
from .VectorLayerScatterplot import VectorLayerScatterplot
266-
from .MeanAndStdDevPlot import MeanAndStdDevPlot
265+
#~ if hasMatplotlib:
266+
#~ from .VectorLayerHistogram import VectorLayerHistogram
267+
#~ from .RasterLayerHistogram import RasterLayerHistogram
268+
#~ from .VectorLayerScatterplot import VectorLayerScatterplot
269+
#~ from .MeanAndStdDevPlot import MeanAndStdDevPlot
270+
#~ from .BarPlot import BarPlot
271+
#~ from .PolarPlot import PolarPlot
272+
273+
#~ self.alglist.extend([
274+
#~ VectorLayerHistogram(), RasterLayerHistogram(),
275+
#~ VectorLayerScatterplot(), MeanAndStdDevPlot(), BarPlot(),
276+
#~ PolarPlot(),
277+
#~ ])
278+
if hasPlotly:
279+
#~ from .VectorLayerHistogram import VectorLayerHistogram
280+
#~ from .RasterLayerHistogram import RasterLayerHistogram
281+
#~ from .VectorLayerScatterplot import VectorLayerScatterplot
282+
#~ from .MeanAndStdDevPlot import MeanAndStdDevPlot
267283
from .BarPlot import BarPlot
268-
from .PolarPlot import PolarPlot
284+
#~ from .PolarPlot import PolarPlot
269285

270-
self.alglist.extend([
271-
VectorLayerHistogram(), RasterLayerHistogram(),
272-
VectorLayerScatterplot(), MeanAndStdDevPlot(), BarPlot(),
273-
PolarPlot(),
274-
])
286+
self.alglist.extend([BarPlot()])
275287

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

0 commit comments

Comments
 (0)