feat(数据可视化技术): 完成实验1任务

- 新增两段文本资源
- 实现词云生成和网络图绘制功能
- 添加《红楼梦》人物关系图交互式展示
This commit is contained in:
dev_xulongjin 2025-04-21 16:27:38 +08:00
parent 38d132913a
commit 47134d7877
8 changed files with 491 additions and 0 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 92 KiB

View File

@ -0,0 +1 @@
The reason for translating afresh Beccarias Dei Delitti e delle Pene (Crimes and Punishments) is, that it is a classical work of its kind, and that the interest which belongs to it is still far from being merely historical

Binary file not shown.

After

Width:  |  Height:  |  Size: 237 KiB

View File

@ -0,0 +1,2 @@
自从1982年这本书的中文版在国内问世以来《万历十五年》就一直畅销经久不衰无论是历史学者还是业余爱好者无论企业老板还是普通白领都能从中获得一些启发和想法。也难怪《人民的名义》里的高玉良都拿着本《万历十五年》刻苦专研。这是因为在这本书中黄仁宇采用了一种新颖的写法让任何人都可以几乎无障碍地去接触正史在他的笔下历史不再是枯燥无味的归总和罗列。这种新颖的写法被黄仁宇本人称为“大历史观”。
所谓“大历史观”既不像编年体史书那样依照时间的脉络叙述一个王朝的兴衰也不像纪传体史书那样单独介绍每个人物的一生而是把历史剖开一个横截面像纪录片导演穿越过去一样把当时的一位皇帝和五位著名的大臣以一种群像式的叙事手法缓缓展开从中折射出16世纪中国社会的完整面貌。并且如同管中窥豹一样从各种细节中观察公元1587年表面一派太平的大明朝为何会一步一步走向衰落和灭亡。那位皇帝自然就是万历皇帝五位大臣分别是大学生张居正和申时行南京督察院都御史海瑞蓟州总兵官戚继光以及前云南姚安知府李贽。用黄仁宇的话来说他们或是身败或是名裂没有一个能够功德圆满。从他们身上可以看出那些隐藏在历史深处的症结已经开始慢慢积累直至无可逆转。

Binary file not shown.

After

Width:  |  Height:  |  Size: 81 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 249 KiB

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,70 @@
from matplotlib import pyplot as plt
import networkx as nx
import matplotlib
matplotlib.use("Tkagg")
peple = [
("贾宝玉", "林黛玉"),("贾宝玉", "薛宝钗"),("林黛玉", "贾母"),("薛宝钗", "薛姨妈"),
("王熙凤", "贾琏"),("王熙凤", "贾母"),("贾宝玉", "贾政"),("贾政", "王夫人"),
("王夫人", "王熙凤"),("史湘云", "贾母"),("李纨", "贾珠"),("贾珠", "王夫人")
]
peple_set = set()
for i in peple:
for j in i:
peple_set.add(j)
people_list = list(peple_set)
G = nx.Graph()
G.add_nodes_from(people_list)
G.add_edges_from(peple)
pos = nx.spring_layout(G)
fig, ax = plt.subplots(figsize=(10, 8))
ax.set_xlim(-1, 1)
ax.set_ylim(-1, 1)
nx.draw_networkx(G, pos, ax=ax, font_family='STHeiti')
def is_within_bounds(x, y):
return -1 <= x <= 1 and -1 <= y <= 1
dragging_node = None
last_x, last_y = None, None
def on_press(event):
global dragging_node, last_x, last_y
for node, (x, y) in pos.items():
if (event.xdata - x) ** 2 + (event.ydata - y) ** 2 < 0.05:
dragging_node = node
last_x, last_y = event.xdata, event.ydata
break
def on_move(event):
global dragging_node, last_x, last_y
if dragging_node is not None:
dx = event.xdata - last_x
dy = event.ydata - last_y
new_x = pos[dragging_node][0] + dx
new_y = pos[dragging_node][1] + dy
if is_within_bounds(new_x,new_y):
pos[dragging_node] = (new_x,new_y)
last_x,last_y = event.xdata,event.ydata
ax.clear()
nx.draw_networkx(G,pos,ax=ax,font_family='STHeiti')
plt.draw()
def on_release(event):
global dragging_node
dragging_node = None
fig.canvas.mpl_connect('button_press_event',on_press)
fig.canvas.mpl_connect('motion_notify_event',on_move)
fig.canvas.mpl_connect('button_release_event',on_release)
plt.show()