ricklupton / ipysankeywidget Goto Github PK
View Code? Open in Web Editor NEWIPython / Jupyter Sankey diagram widget
License: MIT License
IPython / Jupyter Sankey diagram widget
License: MIT License
Hi
I can get ipysankeywidget
working in jupyter (on jupyterhub), but it fails when the notebook is opened with jupyterlab. Here the error:
Error displaying widget
The console shows a bit more information:
Any idea on how to install it on jupyterlab? jupyterlab-manager is well installed, plotly and other ipywidget extension work fine. I can't get ipysankey to load jupyter-sankey-widget
.
Thanks
I am trying to use the ipysankeywidget, and it works fine, but I can't find a way to change the font size of node titles. I have tried setting things by accessing the sankey object like this:
nbsankeyExample.font_style = 'italic'
nbsankeyExample.font_style
u'italic'
, and it returns the value correctly, but when showing the widget again, the value is not used.
Hello,
I would like to know if it is possible to control the maximum iterations for a sankey plot.
I have the impression that this is allowed in d3-sankey-diagram.
If this functionality is not available just for python , I could give it a try
Thanks
In the Quickstart tutorial, I tried my own data from our maintenance records. There are 12 records in one file, and this displays without problems. But, when data collected over a few more days are added, as in the second csv file with 16 records, the chart fails to display.
TwoInputCSVfiles.zip
Windows 10 on Chrome. The code is right (copypasted from the example). I tried both pip and conda installations. The widget is simply not displayed, no error message. I activated the jupyter extensions. This thread was not helpful.
See
Possible fixes:
I am trying to display patient paths using sankey diagrams. I increased the node width using
.node-body { fill: #bbb; stroke: gray; stroke-width: 20px; opacity: 1.0; }
Now I want to change the following
Is there any chance of updating this to make it work with Jupyter Labs? It's a bit tedious to constantly swap between the Lab and Notebook interfaces to see outputs.
Hello
I was using ipsankeywidget with jupyter notebooks but I've recently (today) reinstalled it and was hoping to be able to use on jupyter lab with the new support.
However I am getting an error: Error displaying widget: model not found
even with very simple diagrams. the extensions seem to be correctly installed.
If I try to run the same notebook using the classic notebook I don't get the same error but there is no rendered image.
thanks!
Hi,
I'm running to create multiple sankey diagrams in a for loop and all plots well on jupyter notebook. However, the auto_save_png files sometimes does not look ok. They may be cropped - while colors, etc. (as seen below)
As the png or svg appears sometimes:
Expected output and what is being seen on jupyter notebook:
Do you know if there is a way to overcome this problem?
Hey guys, I encounter a problem with sankey widget.
OS: Ubuntu with nodejs10 and d3-sankey package installed.
Jupyterlab: 1.1.4 with jlab-manager plugin installed
ipywidgets: 7.5.1
python: 3.7.4
browser: chrome and firefox
I make sure ipywidgets works proper but while I test the simple example listed in the document, it shows "Loading widget..." on displaying the sankeywidget object as coding shows below:
layout = Layout(width="500", height="200")
w = SankeyWidget(links=links, margins=dict(top=0, bottom=0, left=50, right=80), layout=layout)
w <- stuck here
I tried to print w.png
and it is ''.
So what's the possible reason and what could I do to get the figure?
Thanks in advance.
When creating a dataset with dim_process
(and also probably with dim_material
and dim_time
, although I didn't try), there is a problem if you try to later use the flow_selection
param when creating a Bundle
. Because the dataset is constructed by adding a prefix source.
and target.
(note the dot), pandas gets angry whenever floweaver.dataset.eval_selection
gets called.
For example, if I have created a Dataset
like so:
import pandas as pd
from floweaver import *
flows = pd.DataFrame(
[['a', 'b', 10],
['a', 'c', 20],
['b', 'b', 5],
['b', 'd', 5],
['c', 'd', 20]],
columns=['source', 'target', 'value']
)
processes = pd.DataFrame(
['fooA', 'fooB', 'fooC', 'fooD'],
columns=['foo'],
index=['a', 'b', 'c', 'd']
)
dataset = Dataset(flows, dim_process=processes)
nodes = {
'node1': ProcessGroup(['a']),
'node2': ProcessGroup(['b', 'c']),
'node3': ProcessGroup(['d']),
'wp': Waypoint(direction='R')
}
ordering = [['node1'], ['node2', 'wp'], ['node3']]
bundles = [
Bundle('node1', 'node2'),
Bundle('node2', 'node2', flow_selection='source.foo == "fooB"', waypoints=['wp']),
Bundle('node2', 'node3'),
]
sdd = SankeyDefinition(nodes, bundles, ordering)
weave(sdd, dataset).to_widget()
This fails with the following traceback:
AttributeError Traceback (most recent call last)
<ipython-input-6-04c4391e4f95> in <module>
33 sdd = SankeyDefinition(nodes, bundles, ordering)
34
---> 35 weave(sdd, dataset).to_widget()
~/.pyenv/versions/3.6.7/envs/flotest/lib/python3.6/site-packages/floweaver/weave.py in weave(sankey_definition, dataset, measures, link_width, link_color, palette)
43 # Get the flows selected by the bundles
44 bundle_flows, unused_flows = dataset.apply_view(
---> 45 sankey_definition.nodes, bundles2, sankey_definition.flow_selection)
46
47 # Calculate the results graph (actual Sankey data)
~/.pyenv/versions/3.6.7/envs/flotest/lib/python3.6/site-packages/floweaver/dataset.py in apply_view(self, process_groups, bundles, flow_selection)
88
89 def apply_view(self, process_groups, bundles, flow_selection=None):
---> 90 return _apply_view(self, process_groups, bundles, flow_selection)
91
92 def save(self, filename):
~/.pyenv/versions/3.6.7/envs/flotest/lib/python3.6/site-packages/floweaver/dataset.py in _apply_view(dataset, process_groups, bundles, flow_selection)
191 target = process_groups[bundle.target]
192 flows, internal_source, internal_target = \
--> 193 find_flows(table, source.selection, target.selection, bundle.flow_selection)
194 assert len(used_edges.intersection(
195 flows.index.values)) == 0, 'duplicate bundle'
~/.pyenv/versions/3.6.7/envs/flotest/lib/python3.6/site-packages/floweaver/dataset.py in find_flows(flows, source_query, target_query, flow_query, ignore_edges)
136 """
137 if flow_query is not None:
--> 138 flows = flows[eval_selection(flows, '', flow_query)]
139
140 if source_query is None and target_query is None:
~/.pyenv/versions/3.6.7/envs/flotest/lib/python3.6/site-packages/floweaver/dataset.py in eval_selection(df, column, sel)
38 local_dict={},
39 global_dict={},
---> 40 resolvers=(resolver, ))
41 else:
42 raise TypeError('Unknown selection type: %s' % type(sel))
~/.pyenv/versions/3.6.7/envs/flotest/lib/python3.6/site-packages/pandas/core/frame.py in eval(self, expr, inplace, **kwargs)
3191 kwargs['target'] = self
3192 kwargs['resolvers'] = kwargs.get('resolvers', ()) + tuple(resolvers)
-> 3193 return _eval(expr, inplace=inplace, **kwargs)
3194
3195 def select_dtypes(self, include=None, exclude=None):
.....
{removed for brevity}
.....
~/.pyenv/versions/3.6.7/envs/flotest/lib/python3.6/site-packages/pandas/core/computation/expr.py in visit_Attribute(self, node, **kwargs)
548
549 raise ValueError("Invalid Attribute context {name}"
--> 550 .format(name=ctx.__name__))
551
552 def visit_Call_35(self, node, side=None, **kwargs):
AttributeError: 'Load' object has no attribute '__name__'
Full traceback here: https://gist.github.com/mskoh52/7054199865c214ad1de8f0e4772582d4
I was able to solve this by editing dataset.py
and replacing all the dots with underscores on lines 28 and 70-77, then replacing flow_selection
string with underscores as well. Can submit a PR if desired, but I might be missing some other places where the dot is important and not realize it (haven't looked too extensively at the rest of the code)
I have spent a reasonable amount trying to figure out why the widget was not appearing and finally I discover it was crashing due to the fact of using a single source.
You can reproduce the error with:
from ipysankeywidget import SankeyWidget
links = [{'source': 'A', 'target': 'R548', 'value': 2},
{'source': 'A', 'target': 'R141', 'value': 2},
{'source': 'A', 'target': 'R141', 'value': 2},
{'source': 'A', 'target': 'R434', 'value': 2}]
w = SankeyWidget(links=links, margins=dict(top=0, bottom=0, left=50, right=100))
I might try to find the fix for it, but I am running out of time at this moment!
Reported by Mike E: changes in height
do not affect size of widget in Internet Explorer.
links = [
{'source':'a_','target':'a','value':0},
{'source':'a_','target':'b','value':4811.5},
{'source':'a_','target':'c','value':6809},
{'source':'b_','target':'a','value':3528.5},
{'source':'b_','target':'b','value':0},
{'source':'b_','target':'c','value':1307},
{'source':'b_','target':'d','value':1342},
]
layout = Layout(width="300", height="100")
def sankey(margin_top=10, **value):
"""Show SankeyWidget with default values for size and margins"""
return SankeyWidget(layout=layout, scale=0.001,
margins=dict(top=margin_top, bottom=0, left=100, right=100),
**value)
sankey(links=links)
Long labels gets cut off.
Sometimes I need long labels.
I've been trying to get it to work all weekend. :'(
Thank you very much for helping!
for example, the image is produced by:
layout = Layout( width="600", height="600", #margins=dict(left=300, right=300, top=50, bottom=50), #paddings=dict(left=300, right=300, top=50, bottom=50), flex_flow='row wrap', overflow = 'visible', border='1px solid black', grid_auto_flow='row', display='block' ) flows = pd.read_csv('simple_fruit_sales.csv') flows['source'] = flows['source'].apply(lambda x: x + "\nblahblah\n100000\n") flows['target'] = flows['target'].apply(lambda x: x + " derpy derp derp") w = SankeyWidget(links=flows.to_dict('records'), layout=layout) w
I am using Chrome together with Jupyter and I am not able to increase the size of the diagram.
I have deduced from here #18 that it must exist some way to do this.
This is what I have tried and it is not working:
SankeyWidget(links=data.to_dict('records'), width=1000, height=900)
Hi,
I was wondering if it'd be possible in an easy way to implement node sorting function in order to reduce cross links on the diagram as much as possible. Some other tools (e.g. Google Charts) can handle this automatically.
Another open sourced visualisation project Raw does it by the code snippet which I copy below:
d3.values(nested)
.forEach(function (d){
var y = ( height() - d3.sum(d,function(n){ return n.dy+sankey.nodePadding();}) ) / 2 + sankey.nodePadding()/2;
d.sort(function (a,b){
if (sortBy() == "automatic") return b.y - a.y;
if (sortBy() == "size") return b.dy - a.dy;
if (sortBy() == "name") return a.name < b.name ? -1 : a.name > b.name ? 1 : 0;
})
d.forEach(function (node){
node.y = y;
y += node.dy +sankey.nodePadding();
})
})
I'd like to do this and contribute. I tried, but I don't have a clue about javascript.
Hello,
I'm facing a weird bug when I try to align different links. It seems that for some reason including numbers in the type name causes some issues.
Example:
The following doesn't work properly
d1 = [
{'source': 'start', 'target': 'E02000314_1', 'value': 32.0, 'type': 't41037'},
{'source': 'E02000314_1', 'target': 'E09000025_2', 'value': 32.0, 'type': 't41037'},
{'source': 'E09000025_2', 'target': 'end', 'value': 32.0, 'type': 't41037'},
{'source': 'start', 'target': 'E02000313_1', 'value': 15.0, 'type': 't39174'},
{'source': 'E02000313_1', 'target': 'E09000025_2', 'value': 15.0, 'type': 't39174'},
{'source': 'E09000025_2', 'target': 'E02000321_3', 'value': 15.0, 'type': 't39174'},
{'source': 'E02000321_3', 'target': 'end', 'value': 15.0, 'type': 't39174'}]
sankey(links=d1, align_link_types=True)
while this does:
d2 = [
{'source': 'start', 'target': 'E02000314_1', 'value': 32.0, 'type': 'Α'},
{'source': 'E02000314_1', 'target': 'E09000025_2', 'value': 32.0, 'type': 'Α'},
{'source': 'E09000025_2', 'target': 'end', 'value': 32.0, 'type': 'Α'},
{'source': 'start', 'target': 'E02000313_1', 'value': 15.0, 'type': 'Β'},
{'source': 'E02000313_1', 'target': 'E09000025_2', 'value': 15.0, 'type': 'Β'},
{'source': 'E09000025_2', 'target': 'E02000321_3', 'value': 15.0, 'type': 'Β'},
{'source': 'E02000321_3', 'target': 'end', 'value': 15.0, 'type': 'Β'}]
sankey(links=d2, align_link_types=True)
I'm happy to try and find a solution but I'd need some initial guidance as to where I should look for. I have a feeling this is an issue of js rather than python right?
Cheers
Hello,
I tried to run the sript "Simple example" and I get the TypeError:
TypeError Traceback (most recent call last)
<ipython-input-10-dda820b7c5a3> in <module>()
1
2
----> 3 w = SankeyWidget(links=links, margins=dict(top=0, bottom=0, left=50, right=100))
TypeError: wrap() got an unexpected keyword argument 'links'
I have anaconda with Python 3.4, it's doesn't work in Spyder and in the qtconsole either.
Is this error known?
Thanks for help and best regards.
It took a little hacking around to get it to install and enable the extension, and I'm still not sure if I got that right, but it seems to work. That is until you try to display the widget. It's blank. Furthermore, if you access the .png
property, it is empty.
Check out my notebook
Hi,
I would like to use ipysankeywidget from an IPython terminal (from spyder actually) to generate Sankey diagram.
If I try the simple example, I can do everything without any error but nothing is displayed.
Is it possible to output the result in a html or svg file from an IPython terminal? I didn't find anything in the documentation.
Thanks for this great project!
I'm not sure how possible this is. This comment suggests it might be doable by wrapping the labels in foreignObjects
: mathjax/MathJax#394 (comment)
In [1]: from ipysankeywidget import SankeyWidget
...:
In [2]: links = [
...: {'source': 'start', 'target': 'A', 'value': 2},
...: {'source': 'A', 'target': 'B', 'value': 2},
...: {'source': 'B', 'target': 'start', 'value': 0.2},
...: {'source': 'C', 'target': 'A', 'value': 2},
...: {'source': 'A', 'target': 'C', 'value': 2},
...: ]
...:
KeyError Traceback (most recent call last)
C:\Users\username\Anaconda3\lib\site-packages\traitlets\traitlets.py in get(self, obj, cls)
525 try:
--> 526 value = obj._trait_values[self.name]
527 except KeyError:
KeyError: 'layout'
During handling of the above exception, another exception occurred:
KeyError Traceback (most recent call last)
C:\Users\username\Anaconda3\lib\site-packages\traitlets\traitlets.py in get(self, obj, cls)
525 try:
--> 526 value = obj._trait_values[self.name]
527 except KeyError:
KeyError: 'kernel'
During handling of the above exception, another exception occurred:
TraitError Traceback (most recent call last)
in ()
1 nbsankeyExample = SankeyWidget(value={'links': links}, width=400, height=200,
----> 2 margins=dict(top=0, bottom=0))
C:\Users\username\Anaconda3\lib\site-packages\ipysankeywidget\sankey_widget.py in init(self, **kwargs)
28 def init(self, **kwargs):
29 """Constructor"""
---> 30 super(SankeyWidget, self).init(**kwargs)
31 self._selected_handlers = widgets.CallbackDispatcher()
32 self._auto_png_filename = None
C:\Users\username\Anaconda3\lib\site-packages\ipywidgets\widgets\domwidget.py in init(self, *pargs, **kwargs)
88
89 def init(self, *pargs, **kwargs):
---> 90 super(DOMWidget, self).init(*pargs, **kwargs)
91
92 # Deprecation added in 5.0. TODO: Remove me and corresponging traits.
C:\Users\username\Anaconda3\lib\site-packages\ipywidgets\widgets\widget.py in init(self, **kwargs)
179 """Public constructor"""
180 self._model_id = kwargs.pop('model_id', None)
--> 181 super(Widget, self).init(**kwargs)
182
183 Widget._call_widget_constructed(self)
C:\Users\username\Anaconda3\lib\site-packages\traitlets\config\configurable.py in init(self, **kwargs)
91 # explicitly assigned values.
92 for key, value in kwargs.items():
---> 93 setattr(self, key, value)
94
95 #-------------------------------------------------------------------------
C:\Users\username\Anaconda3\lib\site-packages\ipywidgets\widgets\domwidget.py in width(self, value)
32 @width.setter
33 def width(self, value): # Removed in ipywidgets 6.0
---> 34 self.layout.width = value
35
36 @Property
C:\Users\username\Anaconda3\lib\site-packages\traitlets\traitlets.py in get(self, obj, cls)
552 return self
553 else:
--> 554 return self.get(obj, cls)
555
556 def set(self, obj, value):
C:\Users\username\Anaconda3\lib\site-packages\traitlets\traitlets.py in get(self, obj, cls)
531 raise TraitError("No default value found for %s trait of %r"
532 % (self.name, obj))
--> 533 value = self._validate(obj, dynamic_default())
534 obj._trait_values[self.name] = value
535 return value
C:\Users\username\Anaconda3\lib\site-packages\ipywidgets\widgets\domwidget.py in _layout_default(self)
21 layout = Instance(Layout, allow_none=True).tag(sync=True, **widget_serialization)
22 def _layout_default(self):
---> 23 return Layout()
24
25 # width, height, padding, margin border properties rebinding to the layout attribute.
C:\Users\username\Anaconda3\lib\site-packages\ipywidgets\widgets\widget.py in init(self, **kwargs)
182
183 Widget._call_widget_constructed(self)
--> 184 self.open()
185
186 def del(self):
C:\Users\username\Anaconda3\lib\site-packages\ipywidgets\widgets\widget.py in open(self)
201 args['comm_id'] = self._model_id
202
--> 203 self.comm = Comm(**args)
204 if buffers:
205 # FIXME: workaround ipykernel missing binary message support in open-on-init
C:\Users\username\Anaconda3\lib\site-packages\ipykernel\comm\comm.py in init(self, target_name, data, metadata, buffers, **kwargs)
54 if self.primary:
55 # I am primary, open my peer.
---> 56 self.open(data=data, metadata=metadata, buffers=buffers)
57 else:
58 self._closed = False
C:\Users\username\Anaconda3\lib\site-packages\ipykernel\comm\comm.py in open(self, data, metadata, buffers)
81 if data is None:
82 data = self._open_data
---> 83 comm_manager = getattr(self.kernel, 'comm_manager', None)
84 if comm_manager is None:
85 raise RuntimeError("Comms cannot be opened without a kernel "
C:\Users\username\Anaconda3\lib\site-packages\traitlets\traitlets.py in get(self, obj, cls)
552 return self
553 else:
--> 554 return self.get(obj, cls)
555
556 def set(self, obj, value):
C:\Users\username\Anaconda3\lib\site-packages\traitlets\traitlets.py in get(self, obj, cls)
531 raise TraitError("No default value found for %s trait of %r"
532 % (self.name, obj))
--> 533 value = self._validate(obj, dynamic_default())
534 obj._trait_values[self.name] = value
535 return value
C:\Users\username\Anaconda3\lib\site-packages\traitlets\traitlets.py in _validate(self, obj, value)
587 return value
588 if hasattr(self, 'validate'):
--> 589 value = self.validate(obj, value)
590 if obj._cross_validation_lock is False:
591 value = self._cross_validate(obj, value)
C:\Users\username\Anaconda3\lib\site-packages\traitlets\traitlets.py in validate(self, obj, value)
1679 return value
1680 else:
-> 1681 self.error(obj, value)
1682
1683 def info(self):
C:\Users\username\Anaconda3\lib\site-packages\traitlets\traitlets.py in error(self, obj, value)
1526 % (self.name, self.info(), msg)
1527
-> 1528 raise TraitError(e)
1529
1530
TraitError: The 'kernel' trait of a Comm instance must be a Kernel, but a value of class 'NoneType' (i.e. None) was specified.
Could not create model:
Model name SankeyModel
Model module jupyter-sankey-widget
Model module version *
Script error for "jupyter-sankey-widget" http://requirejs.org/docs/errors.html#scripterror
Windows 10.
pip list:
alabaster (0.7.7)
anaconda-client (1.4.0)
anaconda-navigator (1.1.0)
argcomplete (1.0.0)
astropy (1.1.2)
Babel (2.2.0)
beautifulsoup4 (4.4.1)
bitarray (0.8.1)
blaze (0.9.1)
bokeh (0.11.1)
boto (2.39.0)
Bottlechest (0.7.1)
Bottleneck (1.0.0)
cffi (1.5.2)
chardet (2.3.0)
chest (0.2.3)
cloudpickle (0.1.1)
clyent (1.2.1)
colorama (0.3.7)
comtypes (1.1.2)
conda (4.3.16)
conda-build (1.20.0)
conda-manager (0.3.1)
configobj (5.0.6)
cryptography (1.4)
cycler (0.10.0)
Cython (0.23.4)
cytoolz (0.7.5)
dask (0.8.1)
datashape (0.5.1)
decorator (4.0.9)
dill (0.2.4)
docutils (0.12)
dynd (c328ab7)
et-xmlfile (1.0.1)
fastcache (1.0.2)
Flask (0.10.1)
Flask-Cors (2.1.2)
gevent (1.1.0)
greenlet (0.4.9)
h5py (2.5.0)
HeapDict (1.0.0)
idna (2.0)
ipykernel (4.6.1)
ipysankeywidget (0.1.6)
ipython (4.1.2)
ipython-d3-sankey (0.1.1)
ipython-genutils (0.1.0)
ipywidgets (6.0.0)
itsdangerous (0.24)
jdcal (1.2)
jedi (0.9.0)
Jinja2 (2.8)
jsonschema (2.4.0)
jupyter (1.0.0)
jupyter-client (4.2.2)
jupyter-console (4.1.1)
jupyter-core (4.1.0)
jupyter-pip (0.3)
llvmlite (0.9.0)
locket (0.2.0)
lxml (3.6.0)
MarkupSafe (0.23)
matplotlib (1.5.1)
menuinst (1.3.2)
mistune (0.7.2)
mpmath (0.19)
multipledispatch (0.4.8)
nbconvert (4.1.0)
nbformat (4.3.0)
networkx (1.11)
nltk (3.2)
nose (1.3.7)
notebook (5.0.0)
numba (0.24.0)
numexpr (2.5)
numpy (1.10.4)
odo (0.4.2)
openpyxl (2.3.2)
Orange (3.2.dev0+dfc525c)
pandas (0.18.0)
partd (0.3.2)
path.py (0.0.0)
patsy (0.4.0)
pep8 (1.7.0)
pickleshare (0.5)
Pillow (3.1.1)
pip (9.0.1)
ply (3.8)
psutil (4.1.0)
py (1.4.31)
pyasn1 (0.1.9)
pycosat (0.6.1)
pycparser (2.14)
pycrypto (2.6.1)
pyflakes (1.1.0)
Pygments (2.1.1)
pyOpenSSL (16.2.0)
pyparsing (2.0.3)
pyqtgraph (0.9.10)
pyreadline (2.1)
pytest (2.8.5)
python-dateutil (2.5.1)
pytz (2016.2)
pywin32 (220)
PyYAML (3.11)
pyzmq (15.2.0)
QtAwesome (0.3.2)
qtconsole (4.2.0)
QtPy (1.0)
requests (2.12.4)
rope-py3k (0.9.4.post1)
scikit-image (0.12.3)
scikit-learn (0.17.1)
scipy (0.17.0)
seaborn (0.7.0)
setuptools (20.3)
simplegeneric (0.8.1)
singledispatch (3.4.0.3)
six (1.10.0)
snowballstemmer (1.2.1)
sockjs-tornado (1.0.1)
Sphinx (1.3.1)
sphinx-rtd-theme (0.1.9)
spyder (2.3.8)
SQLAlchemy (1.0.12)
statsmodels (0.6.1)
sympy (1.0)
tables (3.2.2)
toolz (0.7.4)
tornado (4.3)
tqdm (4.11.2)
traitlets (4.3.2)
unicodecsv (0.14.1)
update (0.4.4)
Werkzeug (0.11.4)
wheel (0.29.0)
widgetsnbextension (2.0.0)
xlrd (0.9.4)
XlsxWriter (0.8.4)
xlwings (0.7.0)
xlwt (1.0.0)
I tried exporting a diagram to SVG and png as in the example. The png works fine. If I right-click the pngimage in my notebook, I can save it. If I try the same for the svg image, I can only save the whole notebook, not the svg image. When I try the same from the example html notebook on your github, I can save the SVG. I tried to find a way to programmatically save the svg, but failed to find one.
I can’t seem to find a way to color differentially the nodes and make them wider than the default setting. I tried to set this up using a dictionary as follows: {'id': 'Anc', 'title': 'Anc', 'style': 'process', 'color': 'blue', 'stroke-width': '20px’}. But unfortunately nothing seems to work. Is there a way to go around this without altering the CSS style?
Hi,
I do have a list of different datasets which I want to visualise in Sankey Diagrams.
I can visualise them one after another, manually but cannot replicate the same in a for loop. An example code is provided below:
from ipysankeywidget import SankeyWidget
links = [
{'source': 'start', 'target': 'A', 'value': 2},
{'source': 'A', 'target': 'B', 'value': 2},
{'source': 'C', 'target': 'A', 'value': 2},
{'source': 'A', 'target': 'C', 'value': 2},
]
w = SankeyWidget(links=links, margins=dict(top=0, bottom=0, left=50, right=100))
for i in [w,w]:
i
For me, it is more important to save Sankey diagrams to a folder rather than printing them in jupyter notebook but they cannot be saved before shown in Jupyter as well. Could you show me a work around to achieve this goal?
Unless I tell it to name the first node 'start' it won't work
It's seems the groups option from d3-sankey-diagram has not been implemented even if it's listed in the advanced examples.
Hi and thanks for the great work!
The following code silently fails (i.e. displays nothing without any error message).
faultylinks = [{'source': 'farm1', 'target': 'client1', 'value': 5}, {'source': 'farm1', 'target': 'client1', 'value': 10}]
SankeyWidget(links=faultylinks)
Obviously, having duplicates in the links should not happen, but I think an error message should be displayed when this happens rather than failing silently.
Not sure if this is due to ipysankeywidget directly, but a safety check could be performed anyway during the init.
I see two distinct solutions:
Solution 2 is easier to implement (there is no logging implemented for now) and probably safer too. Solution 1 focuses on ease of use in case that's what the widget aims for.
I can implement any solution or leave it to you.
Hi!
Since a while I am trying to execute it in Jupyter notebook. Seams that everything works but ... is not displaying a chart. Only white space. I tried to save it as a png but is failing (any file is installed).
I tested it:
What could be a reason that it´s executed but neither displayed nor known?
Thanks!
I am not able to install the widget on a jupyter-lap platform on Ubuntu 18.04.
When running this code
jupyter labextension install jupyter-sankey-widget
I get the following error:
error [email protected]: The platform "linux" is incompatible with this module.
How do I set the link titles? I want to show the link values, preferably on the links, but I can't find a way to do it. Currently I am instead setting the node titles as the values of the links, but it does not look good. In general, how do I access the link appearance functions of d3-sankey-diagram diagram object?
Hello,
I have been using the package for couple of years and it does not work anymore. When I run my old scripts in Jupyter Notebook, I don't see anything. I have installed Jupyter lab and it does not work. I have update the package using the conda line, and updated Jupyter too. Still not working! The codes run fine, the SankeyWidget object is created without error. But I just cannot plot it. Thanks for the help. I have python 3.6.12, ipysankeywidget 0.4.0, ipython 7.12.0, jupyter-notebook 6.2.0.
Hi Rick,
I was wondering if there is a way to code the sankey so that some of the labels attached to nodes are hidden? Couldn't find it in the tutorials.
Cheers
If anyone has experience of building conda packages, or wants to give it a try, it would be great if ipysankeywidget could be installed using conda. I think this just involves putting together a conda recipe.
See also ricklupton/floweaver#43
Any questions let me know by replying below or asking in the chat!
Hi,
I am new to jupyter notebooks, so this problem might be something I'm doing wrong. I've installed the widget and can see it listed and enabled in 'Environment' parameters page using anaconda. I've opened the shared notebook and can import the libraries etc. When I get to calling SankeyWidget (third cell), the kernel is kept busy (I assume this is what is happening seeing I get an asterisk?). Either way, I can't get the diagram to show.
Could you advise?
Thanks
D
Reported by Mike E: trying to display Image(sankey.png)
gives the error:
TypeError: a bytes-like object is required, not 'str'
I have quantities that grow over time so I would like to be able to specify things like:
{'source': 'a', 'target': 'b', 'source_value': 1, 'target_value': 2}
Installing ipysankeywidget seems to install an extension file in notebook.d
which refers to "ipysankeywidget/extension", which I think is wrong -- it should be jupyter-sankey-widget/extension
.
The latter is created in notebook.json when running jupyter nbextension enable --py --sys-prefix ipysankeywidget
Hi,
I'm trying to use sankey diagrams alongside some standard matplotlib plots in an interactive jupyter session by using some widgets. I have a function that calculates the necessary values for each link from some input variables, one of which is an int slider. However when I move the slider around the sankey diagram is redrawn for each slider value rather than being dynamically updated. Could you please advise is there a way to fix this or am I doing something wrong.
Many Thanks,
Hi @ricklupton :
Thanks for your contribution!
Related to what I'm working on(users behaviors flow visualization), the data-set like:
step1 step2 step3
user1 A B C
user2 B C A
user3 C B bounce out
user4 C A C
Can I use the ipysankeywidget to create a flow chart like the attached picture?
Wish to hear from you soon!
Is there anyway to change the color scheme? I can see you're using d3.scale.category20() in the javascript
Can I replace this palette with, say, an seaborn palette? Thanks!
For my application purpose it is required that the node values are displayed (tilted) inside the nodes.
Ideally, I would like to be able to customize the diagram more or less as in the tool below, but with python.
http://sankey.csaladen.es/
Screenshot from tool;
I don't see the possibility to do this as of yet, could this be possible in the future?
Important features for the roadmap:
Hey, thanks for your work :)
Since I have pretty long node titles/names/ids I would like to disable the display of those and purely rely on the tooltips to identify nodes.
Is there an easy way to do that?
Thanks a lot!
I tried reproducing your simple example but received the following error:
TypeError Traceback (most recent call last)
<ipython-input-24-b42a1aad6fb3> in <module>()
----> 1 w = SankeyWidget(links=links, margins=dict(top=0, bottom=0, left=50, right=100))
TypeError: wrap() got an unexpected keyword argument 'links'
Hi,
I followed conda installation instructions for ipysankeywidget and then tried the simple example code but found that a widget did not display using JupyterLab (2.0.1) but did display using Jupyter Notebook.
This is on same computer (MacOS 10.15.4) and same browser (Chrome).
Anaconda Navigator is showing ipsankeywidget 0.3.0 installed and jiupyter-sankey-widget appears in the JupyterLab extension manager.
Chrome developer console shows the following error when executing the layout = Layout(width="500", height="200") line of code.
Executing the sankey command in simple example shows the sankey object but no diagram.
localhost-1585306478218.log
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.