pm4py / pm4py-core

Public repository for the PM4Py (Process Mining for Python) project.
https://pm4py.fit.fraunhofer.de
GNU General Public License v3.0
722 stars 286 forks source link

Visualization in IPython #26

Closed msildatke closed 5 years ago

msildatke commented 5 years ago

Hey,

this is my first time working with GitHub, so i am not really sure how to communicate the best way:

Using IPython (in Spyder) i was not able to visualize the diagrams wihle testing the following example:

from pm4py.algo.discovery.alpha import factory as alpha_miner from pm4py.objects.log.importer.xes import factory as xes_importer from pm4py.visualization.petrinet import factory as vis_factory

log = xes_importer.import_log('') # i of course added the correct path net, initial_marking, final_marking = alpha_miner.apply(log) gviz = vis_factory.apply(net, initial_marking, finalmarking) vis_factory.view(gviz)_

After doing some research i solved the problem by editing the gview.py in pm4py-source/pm4py/visualization/common/ as follows:

def view(gviz): """ View the diagram

Parameters
-----------
gviz
    GraphViz diagram
"""
is_ipynb = False

try:
    get_ipython()
    is_ipynb = True
except NameError:
    # we are not inside Jupyter, do nothing
    pass

if is_ipynb:
    from IPython.display import Image

added / edited Lines

    image = Image(open(gviz.render(), "rb").read())
    from IPython.display import display
    return display(image)
else:
    return gviz.view()

the added commands lead to the correct visualization in IPython-console.

Javert899 commented 5 years ago

Thanks for signaling and for providing a solution!

Your contribution has been integrated in the 'develop' branch and released in the next release

Javert899 commented 5 years ago

Hi, your fix has currently been released in release 1.0.6

Have a nice day