Error related to networkx: ValueError: Received invalid argument(s): size

Asked 2 years ago, Updated 2 years ago, 156 views

import pandas as pd
df =pd.read_csv("C:\\python37\\practice\\textmining\\ccccg\\xxx.csv", encoding='cp949')

galexy_posts=df.get('song')
print(galexy_posts[0:10])

from eunjeon import Mecab
tagger = Mecab()

galexy_stop_words = (chorus) 1 2 3
galexy_stop_words = galexy_stop_words.split(' ')
print(galexy_stop_words[0:10])

galexy_nouns = []
for post in galexy_posts:
    post=str(post).lower()
    for noun in tagger.nouns(post):
        if noun not in galexy_stop_words:
            galexy_nouns.append(noun)

print(galexy_nouns[0:10])  

from collections import Counter
num_top_nouns = 20
galexy_nouns_counter = Counter(galexy_nouns)
galexy_top_nouns = dict(galexy_nouns_counter.most_common(num_top_nouns)) 

import re
import networkx as nx

galexy_sentences = []
for post in galexy_posts:
    galexy_sentences.extend(re.split('; |\.|\?|\!', str(post)))
print(galexy_sentences[0:10])

galexy_sentences_nouns = []
for sentence in galexy_sentences:
    sentence_nouns = tagger.nouns(sentence)
    galexy_sentences_nouns.append(sentence_nouns)
print(galexy_sentences_nouns[0:10])

galexy_word2id = {w: i for i, w in enumerate(galexy_top_nouns.keys())}
print(galexy_word2id)

galexy_id2word = {i: w for i, w in enumerate(galexy_top_nouns.keys())}
print(galexy_id2word)

import numpy as np
galexy_adjacent_matrix = np.zeros((num_top_nouns, num_top_nouns), int)
for sentence in galexy_sentences_nouns:
    for wi, i in galexy_word2id.items():
        if wi in sentence:
            for wj, j in galexy_word2id.items():
                if i != j and wj in sentence:
                    galexy_adjacent_matrix[i][j] += 1
print(galexy_adjacent_matrix)

galexy_network = nx.from_numpy_matrix(galexy_adjacent_matrix)
print(list(galexy_network.adjacency()))

import matplotlib.pyplot as plt
from matplotlib import font_manager as fm
from matplotlib import rc

font_path="C:\\python37\\practice\\textmining\\NanumBarunGothic.ttf"
font_name = fm.FontProperties(fname=font_path).get_name()
rc('font', family=font_name)

fig = plt.figure()
fig.set_size_inches(20, 20)
ax = fig.add_subplot(1, 1, 1)
ax.axis("off")
option = {
    'node_color' : 'lightblue',
    'node_size' : 2000,
    'size' : 2
}
nx.draw(galexy_network, labels=galexy_id2word, font_family=font_name, ax=ax, **option)


Error: 
Traceback (most recent call last):
  File "C:\python37\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "C:\python37\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "c:\Users\baron\.vscode\extensions\ms-python.python-2021.12.1559732655\pythonFiles\lib\python\debugpy\__main__.py", line 45, in <module>
    cli.main()
  File "c:\Users\baron\.vscode\extensions\ms-python.python-2021.12.1559732655\pythonFiles\lib\python\debugpy/..\debugpy\server\cli.py", line 444, in main
    run()
  File "c:\Users\baron\.vscode\extensions\ms-python.python-2021.12.1559732655\pythonFiles\lib\python\debugpy/..\debugpy\server\cli.py", line 285, in run_file
    runpy.run_path(target_as_str, run_name=compat.force_str("__main__"))
  File "C:\python37\lib\runpy.py", line 263, in run_path
    pkg_name=pkg_name, script_name=fname)
  File "C:\python37\lib\runpy.py", line 96, in _run_module_code
    mod_name, mod_spec, pkg_name, script_name)
  File "C:\python37\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "c:\python37\practice\textmining\sib.py", line 78, in <module>
    nx.draw(galexy_network, labels=galexy_id2word, font_family=font_name, ax=ax, **option)
  File "c:\python37\practice\textmining\lib\site-packages\networkx\drawing\nx_pylab.py", line 121, in draw
    draw_networkx(G, pos=pos, ax=ax, **kwds)
  File "c:\python37\practice\textmining\lib\site-packages\networkx\drawing\nx_pylab.py", line 324, in draw_networkx
    raise ValueError(f"Received invalid argument(s): {invalid_args}")
ValueError: Received invalid argument(s): size

What is the cause of the above error?

python mecab matplotlib text-mining

2022-09-20 11:34

1 Answers

It is said that the size agreement specified in the option variable is invalid.


2022-09-20 11:34

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.