mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-15 00:04:00 -04:00
[processing] update bar plot
This commit is contained in:
parent
34b277a09b
commit
46a9891e5c
@ -25,8 +25,11 @@ __copyright__ = '(C) 2013, Victor Olaya'
|
|||||||
|
|
||||||
__revision__ = '$Format:%H$'
|
__revision__ = '$Format:%H$'
|
||||||
|
|
||||||
import matplotlib.pyplot as plt
|
#import matplotlib.pyplot as plt
|
||||||
import matplotlib.pylab as lab
|
#import matplotlib.pylab as lab
|
||||||
|
|
||||||
|
import plotly as plt
|
||||||
|
import plotly.graph_objs as go
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
from processing.core.parameters import ParameterTable
|
from processing.core.parameters import ParameterTable
|
||||||
@ -69,13 +72,8 @@ class BarPlot(GeoAlgorithm):
|
|||||||
output = self.getOutputValue(self.OUTPUT)
|
output = self.getOutputValue(self.OUTPUT)
|
||||||
|
|
||||||
values = vector.values(layer, namefieldname, valuefieldname)
|
values = vector.values(layer, namefieldname, valuefieldname)
|
||||||
plt.close()
|
|
||||||
|
|
||||||
ind = np.arange(len(values[namefieldname]))
|
ind = np.arange(len(values[namefieldname]))
|
||||||
width = 0.8
|
data = [go.Bar(x=ind,
|
||||||
plt.bar(ind, values[valuefieldname], width, color='r')
|
y=values[valuefieldname])]
|
||||||
plt.xticks(ind, values[namefieldname], rotation=45)
|
plt.offline.plot(data, filename=output)
|
||||||
plotFilename = output + '.png'
|
|
||||||
lab.savefig(plotFilename)
|
|
||||||
with open(output, 'w') as f:
|
|
||||||
f.write('<html><img src="' + plotFilename + '"/></html>')
|
|
||||||
|
@ -28,11 +28,14 @@ __revision__ = '$Format:%H$'
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import matplotlib.pyplot
|
#import matplotlib.pyplot
|
||||||
assert matplotlib # NOQA silence pyflakes
|
#assert matplotlib # NOQA silence pyflakes
|
||||||
hasMatplotlib = True
|
#hasMatplotlib = True
|
||||||
|
import plotly
|
||||||
|
hasPlotly = True
|
||||||
except:
|
except:
|
||||||
hasMatplotlib = False
|
#hasMatplotlib = False
|
||||||
|
hasPlotly = False
|
||||||
|
|
||||||
from qgis.PyQt.QtGui import QIcon
|
from qgis.PyQt.QtGui import QIcon
|
||||||
|
|
||||||
@ -259,19 +262,28 @@ class QGISAlgorithmProvider(AlgorithmProvider):
|
|||||||
FixGeometry(), ExecuteSQL(), FindProjection()
|
FixGeometry(), ExecuteSQL(), FindProjection()
|
||||||
]
|
]
|
||||||
|
|
||||||
if hasMatplotlib:
|
#~ if hasMatplotlib:
|
||||||
from .VectorLayerHistogram import VectorLayerHistogram
|
#~ from .VectorLayerHistogram import VectorLayerHistogram
|
||||||
from .RasterLayerHistogram import RasterLayerHistogram
|
#~ from .RasterLayerHistogram import RasterLayerHistogram
|
||||||
from .VectorLayerScatterplot import VectorLayerScatterplot
|
#~ from .VectorLayerScatterplot import VectorLayerScatterplot
|
||||||
from .MeanAndStdDevPlot import MeanAndStdDevPlot
|
#~ from .MeanAndStdDevPlot import MeanAndStdDevPlot
|
||||||
from .BarPlot import BarPlot
|
#~ from .BarPlot import BarPlot
|
||||||
from .PolarPlot import PolarPlot
|
#~ from .PolarPlot import PolarPlot
|
||||||
|
|
||||||
self.alglist.extend([
|
#~ self.alglist.extend([
|
||||||
VectorLayerHistogram(), RasterLayerHistogram(),
|
#~ VectorLayerHistogram(), RasterLayerHistogram(),
|
||||||
VectorLayerScatterplot(), MeanAndStdDevPlot(), BarPlot(),
|
#~ VectorLayerScatterplot(), MeanAndStdDevPlot(), BarPlot(),
|
||||||
PolarPlot(),
|
#~ 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
|
||||||
|
|
||||||
|
self.alglist.extend([BarPlot()])
|
||||||
|
|
||||||
self.externalAlgs = [] # to store algs added by 3rd party plugins as scripts
|
self.externalAlgs = [] # to store algs added by 3rd party plugins as scripts
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user