0
# Visualization Functions
1
2
Extensive visualization capabilities for process models, statistics, and analysis results. PM4PY provides both viewing and saving options for various visualizations including process models, performance charts, and statistical graphs.
3
4
## Capabilities
5
6
### Petri Net Visualization
7
8
Visualize Petri net models with markings, annotations, and custom formatting options.
9
10
```python { .api }
11
def view_petri_net(petri_net, initial_marking=None, final_marking=None, format='png', **kwargs):
12
"""
13
View Petri net visualization in interactive window or notebook.
14
15
Parameters:
16
- petri_net (PetriNet): Petri net model to visualize
17
- initial_marking (Optional[Marking]): Initial marking for visualization
18
- final_marking (Optional[Marking]): Final marking for visualization
19
- format (str): Output format ('png', 'svg', 'pdf')
20
- **kwargs: Additional visualization parameters
21
22
Returns:
23
None: Displays visualization
24
"""
25
26
def save_vis_petri_net(petri_net, initial_marking, final_marking, file_path, **kwargs):
27
"""
28
Save Petri net visualization to file.
29
30
Parameters:
31
- petri_net (PetriNet): Petri net model
32
- initial_marking (Marking): Initial marking
33
- final_marking (Marking): Final marking
34
- file_path (str): Output file path
35
- **kwargs: Additional visualization parameters
36
37
Returns:
38
None: Saves visualization to file
39
"""
40
```
41
42
### DFG Visualization
43
44
Visualize Directly-Follows Graphs with frequency and performance annotations.
45
46
```python { .api }
47
def view_dfg(dfg, start_activities=None, end_activities=None, format='png', **kwargs):
48
"""
49
View Directly-Follows Graph visualization.
50
51
Parameters:
52
- dfg (dict): Directly-follows graph with frequencies
53
- start_activities (Optional[dict]): Start activities and frequencies
54
- end_activities (Optional[dict]): End activities and frequencies
55
- format (str): Output format ('png', 'svg', 'pdf')
56
- **kwargs: Additional visualization parameters
57
58
Returns:
59
None: Displays visualization
60
"""
61
62
def save_vis_dfg(dfg, start_activities, end_activities, file_path, **kwargs):
63
"""
64
Save DFG visualization to file.
65
66
Parameters:
67
- dfg (dict): Directly-follows graph
68
- start_activities (dict): Start activities and frequencies
69
- end_activities (dict): End activities and frequencies
70
- file_path (str): Output file path
71
- **kwargs: Additional visualization parameters
72
73
Returns:
74
None: Saves visualization to file
75
"""
76
77
def view_performance_dfg(dfg, start_activities=None, end_activities=None, format='png', **kwargs):
78
"""
79
View performance DFG with timing information.
80
81
Parameters:
82
- dfg (dict): Performance directly-follows graph
83
- start_activities (Optional[dict]): Start activities
84
- end_activities (Optional[dict]): End activities
85
- format (str): Output format
86
- **kwargs: Additional visualization parameters
87
88
Returns:
89
None: Displays visualization
90
"""
91
92
def save_vis_performance_dfg(dfg, start_activities, end_activities, file_path, **kwargs):
93
"""
94
Save performance DFG visualization to file.
95
96
Parameters:
97
- dfg (dict): Performance directly-follows graph
98
- start_activities (dict): Start activities
99
- end_activities (dict): End activities
100
- file_path (str): Output file path
101
- **kwargs: Additional visualization parameters
102
103
Returns:
104
None: Saves visualization to file
105
"""
106
```
107
108
### Process Tree Visualization
109
110
Visualize hierarchical process tree structures with block compositions.
111
112
```python { .api }
113
def view_process_tree(tree, format='png', **kwargs):
114
"""
115
View process tree visualization showing hierarchical structure.
116
117
Parameters:
118
- tree (ProcessTree): Process tree model
119
- format (str): Output format ('png', 'svg', 'pdf')
120
- **kwargs: Additional visualization parameters
121
122
Returns:
123
None: Displays visualization
124
"""
125
126
def save_vis_process_tree(tree, file_path, **kwargs):
127
"""
128
Save process tree visualization to file.
129
130
Parameters:
131
- tree (ProcessTree): Process tree model
132
- file_path (str): Output file path
133
- **kwargs: Additional visualization parameters
134
135
Returns:
136
None: Saves visualization to file
137
"""
138
```
139
140
### BPMN Visualization
141
142
Visualize Business Process Model and Notation (BPMN) diagrams.
143
144
```python { .api }
145
def view_bpmn(bpmn_graph, format='png', **kwargs):
146
"""
147
View BPMN model visualization.
148
149
Parameters:
150
- bpmn_graph (BPMN): BPMN model object
151
- format (str): Output format ('png', 'svg', 'pdf')
152
- **kwargs: Additional visualization parameters
153
154
Returns:
155
None: Displays visualization
156
"""
157
158
def save_vis_bpmn(bpmn_graph, file_path, **kwargs):
159
"""
160
Save BPMN visualization to file.
161
162
Parameters:
163
- bpmn_graph (BPMN): BPMN model object
164
- file_path (str): Output file path
165
- **kwargs: Additional visualization parameters
166
167
Returns:
168
None: Saves visualization to file
169
"""
170
```
171
172
### Heuristics Net Visualization
173
174
Visualize heuristics nets with dependency information and thresholds.
175
176
```python { .api }
177
def view_heuristics_net(heu_net, format='png', **kwargs):
178
"""
179
View heuristics net visualization with dependency metrics.
180
181
Parameters:
182
- heu_net (HeuristicsNet): Heuristics net object
183
- format (str): Output format ('png', 'svg', 'pdf')
184
- **kwargs: Additional visualization parameters
185
186
Returns:
187
None: Displays visualization
188
"""
189
190
def save_vis_heuristics_net(heu_net, file_path, **kwargs):
191
"""
192
Save heuristics net visualization to file.
193
194
Parameters:
195
- heu_net (HeuristicsNet): Heuristics net object
196
- file_path (str): Output file path
197
- **kwargs: Additional visualization parameters
198
199
Returns:
200
None: Saves visualization to file
201
"""
202
```
203
204
### Object-Centric Visualizations
205
206
Visualize Object-Centric process models and graphs.
207
208
```python { .api }
209
def view_ocdfg(ocdfg, format='png', **kwargs):
210
"""
211
View Object-Centric Directly-Follows Graph visualization.
212
213
Parameters:
214
- ocdfg (dict): Object-centric DFG structure
215
- format (str): Output format ('png', 'svg', 'pdf')
216
- **kwargs: Additional visualization parameters
217
218
Returns:
219
None: Displays visualization
220
"""
221
222
def save_vis_ocdfg(ocdfg, file_path, **kwargs):
223
"""
224
Save OC-DFG visualization to file.
225
226
Parameters:
227
- ocdfg (dict): Object-centric DFG structure
228
- file_path (str): Output file path
229
- **kwargs: Additional visualization parameters
230
231
Returns:
232
None: Saves visualization to file
233
"""
234
235
def view_ocpn(ocpn, format='png', **kwargs):
236
"""
237
View Object-Centric Petri Net visualization.
238
239
Parameters:
240
- ocpn (OCPN): Object-centric Petri net
241
- format (str): Output format ('png', 'svg', 'pdf')
242
- **kwargs: Additional visualization parameters
243
244
Returns:
245
None: Displays visualization
246
"""
247
248
def save_vis_ocpn(ocpn, file_path, **kwargs):
249
"""
250
Save OC-PN visualization to file.
251
252
Parameters:
253
- ocpn (OCPN): Object-centric Petri net
254
- file_path (str): Output file path
255
- **kwargs: Additional visualization parameters
256
257
Returns:
258
None: Saves visualization to file
259
"""
260
261
def view_object_graph(ocel, format='png', **kwargs):
262
"""
263
View object interaction graph from OCEL data.
264
265
Parameters:
266
- ocel (OCEL): Object-centric event log
267
- format (str): Output format ('png', 'svg', 'pdf')
268
- **kwargs: Additional visualization parameters
269
270
Returns:
271
None: Displays visualization
272
"""
273
274
def save_vis_object_graph(ocel, file_path, **kwargs):
275
"""
276
Save object graph visualization to file.
277
278
Parameters:
279
- ocel (OCEL): Object-centric event log
280
- file_path (str): Output file path
281
- **kwargs: Additional visualization parameters
282
283
Returns:
284
None: Saves visualization to file
285
"""
286
```
287
288
### Log-Based Visualizations
289
290
Visualize event log characteristics and patterns.
291
292
```python { .api }
293
def view_sna(sna, format='png', **kwargs):
294
"""
295
View Social Network Analysis visualization.
296
297
Parameters:
298
- sna (SNA): Social network analysis object
299
- format (str): Output format ('png', 'svg', 'pdf')
300
- **kwargs: Additional visualization parameters
301
302
Returns:
303
None: Displays visualization
304
"""
305
306
def save_vis_sna(sna, file_path, **kwargs):
307
"""
308
Save SNA visualization to file.
309
310
Parameters:
311
- sna (SNA): Social network analysis object
312
- file_path (str): Output file path
313
- **kwargs: Additional visualization parameters
314
315
Returns:
316
None: Saves visualization to file
317
"""
318
319
def view_dotted_chart(log, **kwargs):
320
"""
321
View dotted chart showing case timeline patterns.
322
323
Parameters:
324
- log (Union[EventLog, pd.DataFrame]): Event log data
325
- **kwargs: Additional visualization parameters
326
327
Returns:
328
None: Displays visualization
329
"""
330
331
def save_vis_dotted_chart(log, file_path, **kwargs):
332
"""
333
Save dotted chart to file.
334
335
Parameters:
336
- log (Union[EventLog, pd.DataFrame]): Event log data
337
- file_path (str): Output file path
338
- **kwargs: Additional visualization parameters
339
340
Returns:
341
None: Saves visualization to file
342
"""
343
344
def view_performance_spectrum(log, **kwargs):
345
"""
346
View performance spectrum visualization showing case durations.
347
348
Parameters:
349
- log (Union[EventLog, pd.DataFrame]): Event log data
350
- **kwargs: Additional visualization parameters
351
352
Returns:
353
None: Displays visualization
354
"""
355
356
def save_vis_performance_spectrum(log, file_path, **kwargs):
357
"""
358
Save performance spectrum to file.
359
360
Parameters:
361
- log (Union[EventLog, pd.DataFrame]): Event log data
362
- file_path (str): Output file path
363
- **kwargs: Additional visualization parameters
364
365
Returns:
366
None: Saves visualization to file
367
"""
368
```
369
370
### Statistical Charts
371
372
Generate statistical visualizations for process analysis.
373
374
```python { .api }
375
def view_case_duration_graph(log, **kwargs):
376
"""
377
View case duration distribution graph.
378
379
Parameters:
380
- log (Union[EventLog, pd.DataFrame]): Event log data
381
- **kwargs: Additional visualization parameters
382
383
Returns:
384
None: Displays visualization
385
"""
386
387
def save_vis_case_duration_graph(log, file_path, **kwargs):
388
"""
389
Save case duration graph to file.
390
391
Parameters:
392
- log (Union[EventLog, pd.DataFrame]): Event log data
393
- file_path (str): Output file path
394
- **kwargs: Additional visualization parameters
395
396
Returns:
397
None: Saves visualization to file
398
"""
399
400
def view_events_per_time_graph(log, **kwargs):
401
"""
402
View events per time period graph showing activity patterns.
403
404
Parameters:
405
- log (Union[EventLog, pd.DataFrame]): Event log data
406
- **kwargs: Additional visualization parameters
407
408
Returns:
409
None: Displays visualization
410
"""
411
412
def save_vis_events_per_time_graph(log, file_path, **kwargs):
413
"""
414
Save events per time graph to file.
415
416
Parameters:
417
- log (Union[EventLog, pd.DataFrame]): Event log data
418
- file_path (str): Output file path
419
- **kwargs: Additional visualization parameters
420
421
Returns:
422
None: Saves visualization to file
423
"""
424
425
def view_events_distribution_graph(log, **kwargs):
426
"""
427
View events distribution graph showing frequency patterns.
428
429
Parameters:
430
- log (Union[EventLog, pd.DataFrame]): Event log data
431
- **kwargs: Additional visualization parameters
432
433
Returns:
434
None: Displays visualization
435
"""
436
437
def save_vis_events_distribution_graph(log, file_path, **kwargs):
438
"""
439
Save events distribution graph to file.
440
441
Parameters:
442
- log (Union[EventLog, pd.DataFrame]): Event log data
443
- file_path (str): Output file path
444
- **kwargs: Additional visualization parameters
445
446
Returns:
447
None: Saves visualization to file
448
"""
449
```
450
451
### Advanced Visualizations
452
453
Specialized visualizations for complex analysis tasks.
454
455
```python { .api }
456
def view_network_analysis(log, **kwargs):
457
"""
458
View network analysis visualization for organizational mining.
459
460
Parameters:
461
- log (Union[EventLog, pd.DataFrame]): Event log data
462
- **kwargs: Additional visualization parameters
463
464
Returns:
465
None: Displays visualization
466
"""
467
468
def save_vis_network_analysis(log, file_path, **kwargs):
469
"""
470
Save network analysis to file.
471
472
Parameters:
473
- log (Union[EventLog, pd.DataFrame]): Event log data
474
- file_path (str): Output file path
475
- **kwargs: Additional visualization parameters
476
477
Returns:
478
None: Saves visualization to file
479
"""
480
481
def view_transition_system(transition_system, **kwargs):
482
"""
483
View transition system visualization showing state space.
484
485
Parameters:
486
- transition_system (TransitionSystem): Transition system model
487
- **kwargs: Additional visualization parameters
488
489
Returns:
490
None: Displays visualization
491
"""
492
493
def save_vis_transition_system(transition_system, file_path, **kwargs):
494
"""
495
Save transition system visualization to file.
496
497
Parameters:
498
- transition_system (TransitionSystem): Transition system model
499
- file_path (str): Output file path
500
- **kwargs: Additional visualization parameters
501
502
Returns:
503
None: Saves visualization to file
504
"""
505
506
def view_prefix_tree(prefix_tree, **kwargs):
507
"""
508
View prefix tree visualization showing trace structure.
509
510
Parameters:
511
- prefix_tree (Trie): Prefix tree structure
512
- **kwargs: Additional visualization parameters
513
514
Returns:
515
None: Displays visualization
516
"""
517
518
def save_vis_prefix_tree(prefix_tree, file_path, **kwargs):
519
"""
520
Save prefix tree visualization to file.
521
522
Parameters:
523
- prefix_tree (Trie): Prefix tree structure
524
- file_path (str): Output file path
525
- **kwargs: Additional visualization parameters
526
527
Returns:
528
None: Saves visualization to file
529
"""
530
531
def view_alignments(alignments, **kwargs):
532
"""
533
View alignment visualization showing trace-model mapping.
534
535
Parameters:
536
- alignments (List): Alignment results
537
- **kwargs: Additional visualization parameters
538
539
Returns:
540
None: Displays visualization
541
"""
542
543
def save_vis_alignments(alignments, file_path, **kwargs):
544
"""
545
Save alignment visualization to file.
546
547
Parameters:
548
- alignments (List): Alignment results
549
- file_path (str): Output file path
550
- **kwargs: Additional visualization parameters
551
552
Returns:
553
None: Saves visualization to file
554
"""
555
556
def view_footprints(footprints, **kwargs):
557
"""
558
View footprints visualization for model comparison.
559
560
Parameters:
561
- footprints (Dict): Footprints structure
562
- **kwargs: Additional visualization parameters
563
564
Returns:
565
None: Displays visualization
566
"""
567
568
def save_vis_footprints(footprints, file_path, **kwargs):
569
"""
570
Save footprints visualization to file.
571
572
Parameters:
573
- footprints (Dict): Footprints structure
574
- file_path (str): Output file path
575
- **kwargs: Additional visualization parameters
576
577
Returns:
578
None: Saves visualization to file
579
"""
580
581
def view_powl(powl_model, **kwargs):
582
"""
583
View POWL model visualization.
584
585
Parameters:
586
- powl_model (POWL): POWL model object
587
- **kwargs: Additional visualization parameters
588
589
Returns:
590
None: Displays visualization
591
"""
592
593
def save_vis_powl(powl_model, file_path, **kwargs):
594
"""
595
Save POWL visualization to file.
596
597
Parameters:
598
- powl_model (POWL): POWL model object
599
- file_path (str): Output file path
600
- **kwargs: Additional visualization parameters
601
602
Returns:
603
None: Saves visualization to file
604
"""
605
```
606
607
## Usage Examples
608
609
### Basic Process Model Visualization
610
611
```python
612
import pm4py
613
614
# Load log and discover model
615
log = pm4py.read_xes('event_log.xes')
616
net, initial_marking, final_marking = pm4py.discover_petri_net_inductive(log)
617
618
# View Petri net in interactive window/notebook
619
pm4py.view_petri_net(net, initial_marking, final_marking)
620
621
# Save Petri net to file
622
pm4py.save_vis_petri_net(net, initial_marking, final_marking, 'petri_net.png')
623
624
# View process tree
625
tree = pm4py.discover_process_tree_inductive(log)
626
pm4py.view_process_tree(tree)
627
pm4py.save_vis_process_tree(tree, 'process_tree.svg')
628
```
629
630
### DFG and Performance Visualization
631
632
```python
633
import pm4py
634
635
# Discover and visualize DFG
636
dfg, start_activities, end_activities = pm4py.discover_dfg(log)
637
pm4py.view_dfg(dfg, start_activities, end_activities)
638
639
# Discover and visualize performance DFG
640
perf_dfg, start_acts, end_acts = pm4py.discover_performance_dfg(log)
641
pm4py.view_performance_dfg(perf_dfg, start_acts, end_acts)
642
643
# Save DFG visualizations
644
pm4py.save_vis_dfg(dfg, start_activities, end_activities, 'dfg_frequency.png')
645
pm4py.save_vis_performance_dfg(perf_dfg, start_acts, end_acts, 'dfg_performance.png')
646
```
647
648
### Statistical Visualizations
649
650
```python
651
import pm4py
652
653
# View case duration distribution
654
pm4py.view_case_duration_graph(log)
655
656
# View events per time period
657
pm4py.view_events_per_time_graph(log)
658
659
# View events distribution
660
pm4py.view_events_distribution_graph(log)
661
662
# View dotted chart for timeline analysis
663
pm4py.view_dotted_chart(log)
664
665
# View performance spectrum
666
pm4py.view_performance_spectrum(log)
667
668
# Save all statistical charts
669
pm4py.save_vis_case_duration_graph(log, 'case_durations.png')
670
pm4py.save_vis_events_per_time_graph(log, 'events_timeline.png')
671
pm4py.save_vis_events_distribution_graph(log, 'events_distribution.png')
672
pm4py.save_vis_dotted_chart(log, 'dotted_chart.png')
673
pm4py.save_vis_performance_spectrum(log, 'performance_spectrum.png')
674
```
675
676
### Object-Centric Visualizations
677
678
```python
679
import pm4py
680
681
# Load OCEL and create visualizations
682
ocel = pm4py.read_ocel('ocel_data.csv')
683
684
# Discover and visualize OC-DFG
685
ocdfg = pm4py.discover_ocdfg(ocel)
686
pm4py.view_ocdfg(ocdfg)
687
pm4py.save_vis_ocdfg(ocdfg, 'ocdfg.png')
688
689
# Visualize object interaction graph
690
pm4py.view_object_graph(ocel)
691
pm4py.save_vis_object_graph(ocel, 'object_graph.png')
692
693
# Discover and visualize OC Petri net
694
ocpn = pm4py.discover_oc_petri_net(ocel)
695
pm4py.view_ocpn(ocpn)
696
pm4py.save_vis_ocpn(ocpn, 'ocpn.png')
697
```
698
699
### Organizational and Social Network Visualization
700
701
```python
702
import pm4py
703
704
# Discover handover network
705
sna = pm4py.discover_handover_of_work_network(log)
706
pm4py.view_sna(sna)
707
pm4py.save_vis_sna(sna, 'handover_network.png')
708
709
# Network analysis visualization
710
pm4py.view_network_analysis(log)
711
pm4py.save_vis_network_analysis(log, 'network_analysis.png')
712
```
713
714
### Advanced Model Visualizations
715
716
```python
717
import pm4py
718
719
# Discover and visualize transition system
720
ts = pm4py.discover_transition_system(log)
721
pm4py.view_transition_system(ts)
722
pm4py.save_vis_transition_system(ts, 'transition_system.png')
723
724
# Discover and visualize prefix tree
725
prefix_tree = pm4py.discover_prefix_tree(log)
726
pm4py.view_prefix_tree(prefix_tree)
727
pm4py.save_vis_prefix_tree(prefix_tree, 'prefix_tree.png')
728
729
# Discover and visualize POWL model
730
powl_model = pm4py.discover_powl(log)
731
pm4py.view_powl(powl_model)
732
pm4py.save_vis_powl(powl_model, 'powl_model.png')
733
734
# Visualize BPMN model
735
bpmn = pm4py.discover_bpmn_inductive(log)
736
pm4py.view_bpmn(bpmn)
737
pm4py.save_vis_bpmn(bpmn, 'bpmn_model.png')
738
```
739
740
### Conformance Visualization
741
742
```python
743
import pm4py
744
745
# Get alignments and visualize
746
alignments = pm4py.conformance_diagnostics_alignments(log, net, initial_marking, final_marking)
747
pm4py.view_alignments(alignments)
748
pm4py.save_vis_alignments(alignments, 'alignments.png')
749
750
# Discover and visualize footprints
751
footprints = pm4py.discover_footprints(log)
752
pm4py.view_footprints(footprints)
753
pm4py.save_vis_footprints(footprints, 'footprints.png')
754
```
755
756
### Visualization with Custom Parameters
757
758
```python
759
import pm4py
760
761
# Custom DFG visualization with parameters
762
pm4py.view_dfg(
763
dfg, start_activities, end_activities,
764
format='svg',
765
bgcolor='white',
766
rankdir='TB', # Top to bottom layout
767
fontsize=12,
768
edge_color='blue'
769
)
770
771
# Custom Petri net with annotations
772
pm4py.view_petri_net(
773
net, initial_marking, final_marking,
774
format='pdf',
775
show_labels=True,
776
show_initial_marking=True,
777
show_final_marking=True,
778
decorations={'frequency': True}
779
)
780
781
# High-resolution export
782
pm4py.save_vis_process_tree(
783
tree, 'high_res_tree.png',
784
dpi=300,
785
bgcolor='transparent',
786
fontsize=14
787
)
788
```
789
790
### Batch Visualization Creation
791
792
```python
793
import pm4py
794
import os
795
796
def create_full_analysis_report(log, output_dir='analysis_output'):
797
"""Create comprehensive visualization report."""
798
799
os.makedirs(output_dir, exist_ok=True)
800
801
# Discover models
802
net, im, fm = pm4py.discover_petri_net_inductive(log)
803
tree = pm4py.discover_process_tree_inductive(log)
804
dfg, start_acts, end_acts = pm4py.discover_dfg(log)
805
perf_dfg, perf_start, perf_end = pm4py.discover_performance_dfg(log)
806
807
# Save process models
808
pm4py.save_vis_petri_net(net, im, fm, f'{output_dir}/petri_net.png')
809
pm4py.save_vis_process_tree(tree, f'{output_dir}/process_tree.png')
810
pm4py.save_vis_dfg(dfg, start_acts, end_acts, f'{output_dir}/dfg.png')
811
pm4py.save_vis_performance_dfg(perf_dfg, perf_start, perf_end, f'{output_dir}/perf_dfg.png')
812
813
# Save statistical charts
814
pm4py.save_vis_case_duration_graph(log, f'{output_dir}/case_durations.png')
815
pm4py.save_vis_events_per_time_graph(log, f'{output_dir}/events_timeline.png')
816
pm4py.save_vis_dotted_chart(log, f'{output_dir}/dotted_chart.png')
817
pm4py.save_vis_performance_spectrum(log, f'{output_dir}/performance_spectrum.png')
818
819
# Organizational analysis
820
sna = pm4py.discover_handover_of_work_network(log)
821
pm4py.save_vis_sna(sna, f'{output_dir}/handover_network.png')
822
823
print(f"Analysis report saved to {output_dir}/")
824
825
# Create full analysis
826
create_full_analysis_report(log)
827
```