Giter VIP home page Giter VIP logo

dataplotly's Introduction

DataPlotly

QGIS.org Test plugin Transifex ๐Ÿ—บ

The DataPlotly plugin allows creation of D3-like interactive plots directly within QGIS, thanks to the Plotly library and its Python API.

DataPlotly makes plot creation and customization easy for every needs.

Besides all the plot and customization available, the plot is linked with the QGIS map canvas:

Plot interactions

Plot interactions

Usage

DataPlotly works only with QGIS 3. No additional libraries are necessary.

Gallery

Single Plot

Some examples of single plot type with some options. The list is far away to show all the possibilities.

Scatter Plot

Plot interactions

Box Plot with statistics

Plot interactions

Violin Plot

Plot interactions

Stacked Bar Plot

Plot interactions

Probability Histogram

Plot interactions

Pie Chart

Plot interactions

2D Histogram

Plot interactions

Polar Plot

Plot interactions

Ternary Plot

Plot interactions

Contour Plot

Plot interactions

Multi Plots

DataPloty allows creation of different plot type in the same plot canvas but also allows the chance to separate each plot in a different canvas.

Some plot are not compatible with overlapping or subplotting. A message will warn you when this happens.

Overlapped Plots

Plot interactions

Subplots in row

Plot interactions

Subplots in column

Plot interactions

dataplotly's People

Contributors

agiudiceandrea avatar enricofer avatar ghtmtt avatar giliam avatar gustry avatar jdlom avatar jdugge avatar jmonticolo avatar leonmvd avatar libremente avatar m-kuhn avatar mach0 avatar mdouchin avatar nyalldawson avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

dataplotly's Issues

Feature selection when subplotting

When subplotting in rows or columns from different vector sources, the selection tool works only of the last vector (so last plot) and the first one is ignored.

Currently in dialog the js callback function works like this:

if dic['mode'] == 'selection':
    if dic['type'] == 'scatter':
        self.layer_combo.currentLayer().selectByIds(dic['id'])
    else:
        self.layer_combo.currentLayer().selectByIds(dic['tid'])

maybe in plot, together with the other variables takes also the QgsVectorLayer object should be taken.

No stacked/overlay histograms

This happens because each plot has its own Layout while to create stack or overlay histograms the layout must be just one..

This sounds like a small code reviewing...

Some plots are not rendered in QWebView (Scatter Plot 3D, Contour, Heatmap)

Apparently the code works (dict is filled with correct values etc), the base plot (grid, axes, etc) is visible in the QWebView, but no points or lines appear in the plot.

This happens with the following:

  • ScatterPlot 3D
  • Heatmap
  • Contour

Not working solution it to locally save the plotly.js file and load it in the html file. In this case nothing is loaded in the QWebView

Create Processing module

Could be worth to have also a Processing module that calls DataPlotly API and creates the plot, something like:
selection_002

the method should create some kind of output (dictionary, json...) that will be elaborated by a method of the plugin.
Finally a QWebView should be opened (with the js interaction)

Webkit import error on install

I just installed 2.99 on linux 17.10. I tired to install the plugin and got the following error -

Couldn't load plugin 'DataPlotly' due to an error when calling its classFactory() method

ModuleNotFoundError: No module named 'PyQt5.QtWebKit'
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/qgis/utils.py", line 336, in startPlugin
plugins[packageName] = package.classFactory(iface)
File "/home/uncle/.local/share/QGIS/QGIS3/profiles/default/python/plugins/DataPlotly/init.py", line 34, in classFactory
from .data_plotly import DataPlotly
File "/usr/lib/python3/dist-packages/qgis/utils.py", line 664, in _import
mod = _builtin_import(name, globals, locals, fromlist, level)
File "/home/uncle/.local/share/QGIS/QGIS3/profiles/default/python/plugins/DataPlotly/data_plotly.py", line 30, in
from DataPlotly.data_plotly_dialog import DataPlotlyDockWidget
File "/usr/lib/python3/dist-packages/qgis/utils.py", line 664, in _import
mod = _builtin_import(name, globals, locals, fromlist, level)
File "/home/uncle/.local/share/QGIS/QGIS3/profiles/default/python/plugins/DataPlotly/data_plotly_dialog.py", line 31, in
from PyQt5.QtWebKit import QWebSettings
File "/usr/lib/python3/dist-packages/qgis/utils.py", line 664, in _import
mod = _builtin_import(name, globals, locals, fromlist, level)
ModuleNotFoundError: No module named 'PyQt5.QtWebKit'

Saving static images

Consider to change how to save the images also using directly plotly API: https://plot.ly/python/static-image-export/

Could be tricky for subplotting or for more plot in the same plot canvas.

Small code sample:

import plotly
import plotly.graph_objs as go

vl = iface.activeLayer()

f1 = []
for i in vl.getFeatures():
    f1.append(i['PH'])
    
f2 = []
for i in vl.getFeatures():
    f2.append(i['EC'])


trace1 = go.Scatter(
x = f1,
y = f2
)

layout = go.Layout(
    showlegend = True
)


data = [trace1]
fig = go.Figure(data=data, layout = layout)
plotly.offline.plot(fig,  image='svg')

Marker size from vector field

QgsDataDefinedButton does not exist anymore, it has been replaced with QgsPropertyOverrideButton: http://qgis.org/api/classQgsPropertyOverrideButton.html

here a code snippet to run it from the python console:

from qgis.gui import QgsPropertyOverrideButton
btn = QgsPropertyOverrideButton()
btn.show()

and here an old question on how to connect the vector layer to the button: https://gis.stackexchange.com/questions/193120/how-to-connect-qgsmaplayercombobox-to-qgsdatadefinedbutton

Facet plots

From version 2.0.12 the facet plotting is available. A third variable can be used for plotting just the category:

https://plot.ly/python/facet-trellis/

seems very easy to implement, but be aware of the plotly version installed

Handling errors and refreshing the QWebView

Many errors are already handled with the MessageBar widget, some more needed:

Errors:

  • Draw button when basket is empty

WebView:

  • new plot added to the basket after the first plot is already created, view needs refresh. Refreshing function linked to DRAW button
  • empty basket button also the view should be blank
  • make some check with the plots and subplots
  • remove single plot from basket should refresh the QWebView

Mean and stdev lines

What about adding mean and stdev lines in a plot? Seems simple with shapes

https://plot.ly/python/shapes/

at least for scatterplot and histograms. Code snippet:

layout = { 
  "shapes": [
    {
      "fillcolor": "blue", 
      "line": {
        "color": "blue", 
        "width": 1
      }, 
      "type": "line", 
      "x0": -90422231, 
      "x1": 3104496578, 
      "xref": "x", 
      "y0": 5, 
      "y1": 5, 
      "yref": "y"
    }
]}

Save plot status within the project?

In could be useful to have also some way to have the plot configurations saved within the project.
The code should allow that easy, but the way to implement it has to be straightforward

import external files

it would be useful to analyze vectors not present in the TOC; would it be easy to add a button as in the figure?
image

Animations are available for offline

A bit complicated to implement, but the code is more or less straightforward:

f1 = [125.7, 219.12, 298.55, 132.32, 520.6, 3435.49, 2322.61, 1891.63, 216.97, 383.98, 82.01, 365.56, 199.98, 308.71, 217.58, 436.09, 711.77]
f2 = [1046.67, 1315.0, 1418.0, 997.33, 2972.3, 9700.0, 6726.0, 6002.5, 2096.0, 2470.0, 867.0, 2201.7, 1685.6, 2416.7, 1618.3, 2410.0, 2962.0]


trace1 = go.Scatter(
x = f1,
y = f2,
mode = 'markers'
)

layout = go.Layout(
    xaxis = dict(range=[min(f1), max(f1)], autorange=False),
    yaxis = dict(range=[min(f2), max(f2)], autorange=False),
    updatemenus = [{'type': 'buttons', 'buttons': 
        [{'label': 'Play',
        'method': 'animate',
        'args': [None]},
        {'label': 'Pause',
        'method': 'animate',
        'args': [[None], 
        {'frame' : {'duration':0, 'redraw': False}, 'mode':'immediate'},
        ]}
        ]}],
)


frames= []
for i, j in zip(f1, f2):
    frames.append({'data': [{'x': [i], 'y': [j]}]})

data = [trace1]
fig = go.Figure(data=data, layout = layout, frames=frames)
plotly.offline.plot(fig)

API here

https://plot.ly/python/animations/#moving-frenet-frame-along-a-planar-curve

Update selection when already a selection is made

If the plot is made with the selected features checkbox, the expression (and the selection) is correct, but it loops in all the attribute table and not just in the feature subset.

Handling this is quite tricky.

QWebView and QWidget

Problem with the plot and the QWebView is the html generated. By avoiding to export the javascript into the html and adding just the link to it, it works nice in the QWebView.

Something like this:

        self.plot_html = '<head><meta charset="utf-8" /></head>''<head><meta charset="utf-8" /><script src="https://cdn.plot.ly/plotly-latest.min.js"></script></head>'
        self.plot_html += plotly.offline.plot(fig, output_type='div', include_plotlyjs=False)
        self.plot_html += '</body></html>'
  1. run the above code
  2. save the html in the tmp folder (see also #6)
  3. load the created html into the view

THE BUTTON TO SAVE THE PLOT STILL DOES NOT WORK, so find a way to a way to add a button to take a screenshot of the webview

Axis enhancements

  • revert axis checkbox
  • some axis transformation (log, ln, exp...)
  • dx and dy axis start and stop (like ranges) boxes?
  • double axis in the same plot?

Scatter3D makes QGIS crash

Scatter3D plots are in the plots folder and ready to use. Work fine except when emptying the plot basket or removing a single 3D trace (or having some normal error when overlapping different plots).
QGIS crashed (also on WIN), difficult to understand the cause:

QGIS died on signal 11Could not attach to process.  If your uid matches the uid of the target
process, check the setting of /proc/sys/kernel/yama/ptrace_scope, or try
again as the root user.  For more details, see /etc/sysctl.d/10-ptrace.conf
ptrace: Operation not permitted.
No thread selected
No stack.
gdb returned 0
Aborted

Button to save the plot

Native plotly save plot button does not work.

Solution is to create an additional button to save the plot as a screenshot of the webview in a folder chosen by the user

No module named PyQt5.QtWebKit

Trying to install the plugin on QGIS 3 built from source I get the following error message - No module named PyQt5.QtWebKit
Running:

QGIS version 2.99.0-Master QGIS code revision a0819053fd
Compiled against Qt 5.7.1 Running against Qt 5.7.1
Compiled against GDAL/OGR 2.1.2 Running against GDAL/OGR 2.1.2
Compiled against GEOS 3.5.1-CAPI-1.9.1 Running against GEOS 3.5.1-CAPI-1.9.1 r4246
PostgreSQL Client Version 9.6.5 SpatiaLite Version 4.3.0a
QWT Version 6.1.2 PROJ.4 Version 493
QScintilla2 Version 2.9.3 This copy of QGIS writes debugging output.

Any pointers what could be wrong?

Box plot error when no X field is defined

Should be easy to fix:

Traceback (most recent call last):
  File "/home/matteo/.local/share/QGIS/QGIS3/profiles/matteo/python/plugins/DataPlotly/data_plotly_dialog.py", line 750, in createPlot
    self.plotProperties()
  File "/home/matteo/.local/share/QGIS/QGIS3/profiles/matteo/python/plugins/DataPlotly/data_plotly_dialog.py", line 675, in plotProperties
    'featureBox':getSortedId(self.layer_combo.currentLayer(), xx),
  File "/home/matteo/.local/share/QGIS/QGIS3/profiles/matteo/python/plugins/DataPlotly/utils.py", line 53, in getSortedId
    if type(field_list[0]) == (int or float):
IndexError: list index out of range

Show label on plot

add a checkbox to let the user choose to display the labels on the points in the plot

Remove traces from plot and other buttons

The current Plot Basket tab is useless because the remove trace button is not doing anything.
Maybe by removing the tab and all the options related the layout of the plugin will be cleaner and maybe that options are not super useful for the users.

having just the Clean Plot Canvas and Create Plot buttons is good, but maybe it is worth, when the first plot is created (i.e. Create Plot is hit the first time) to give some option to overlap the plots (SinglePlot)or put the other plots in rows and columns (SubPlots)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.