mckinsey / causalnex

A Python library that helps data scientists to infer causation rather than observing correlation.
http://causalnex.readthedocs.io/
Other
2.21k stars 256 forks source link

An issue with plotting[Bug]: #229

Open mohammadoshanreh opened 5 months ago

mohammadoshanreh commented 5 months ago

Contact Details

oshanreh@uw.edu

Short description of the problem here.

Hi. I am trying to replicate the first tutorial. I cannot plot the graph and I got this error: Screenshot 2024-04-09 092924

Can you help me with this?

CausalNex Version

0.12.1

Python Version

3.8.19

Relevant code snippet

from causalnex.plots import plot_structure, NODE_STYLE, EDGE_STYLE

viz = plot_structure(
    sm,
    all_node_attributes=NODE_STYLE.WEAK,
    all_edge_attributes=EDGE_STYLE.WEAK,
)
viz.show("01_simple_plot.html")

Relevant log output

---------------------------------------------------------------------------
UnicodeEncodeError                        Traceback (most recent call last)
Cell In[6], line 8
      1 from causalnex.plots import plot_structure, NODE_STYLE, EDGE_STYLE
      3 viz = plot_structure(
      4     sm,
      5     all_node_attributes=NODE_STYLE.WEAK,
      6     all_edge_attributes=EDGE_STYLE.WEAK,
      7 )
----> 8 viz.show("01_simple_plot.html")

File ~\anaconda3\envs\m3\lib\site-packages\pyvis\network.py:546, in Network.show(self, name, local, notebook)
    544 print(name)
    545 if notebook:
--> 546     self.write_html(name, open_browser=False,notebook=True)
    547 else:
    548     self.write_html(name, open_browser=True)

File ~\anaconda3\envs\m3\lib\site-packages\pyvis\network.py:530, in Network.write_html(self, name, local, notebook, open_browser)
    528 elif self.cdn_resources == "in_line" or self.cdn_resources == "remote":
    529     with open(getcwd_name, "w+") as out:
--> 530         out.write(self.html)
    531 else:
    532     assert "cdn_resources is not in ['in_line','remote','local']."

File ~\anaconda3\envs\m3\lib\encodings\cp1252.py:19, in IncrementalEncoder.encode(self, input, final)
     18 def encode(self, input, final=False):
---> 19     return codecs.charmap_encode(input,self.errors,encoding_table)[0]

UnicodeEncodeError: 'charmap' codec can't encode characters in position 263607-263621: character maps to <undefined>

Code of Conduct

dvirzg commented 3 months ago

Do you have the installation prerequisites, i.e. PyTorch and PyGraphViz and did you run your code in a conda environment? That should fix it.