feat(数据可视化技术): 完成实验1任务
- 新增两段文本资源 - 实现词云生成和网络图绘制功能 - 添加《红楼梦》人物关系图交互式展示
This commit is contained in:
parent
38d132913a
commit
47134d7877
BIN
数据可视化技术/实验1/resource/1.png
Executable file
BIN
数据可视化技术/实验1/resource/1.png
Executable file
Binary file not shown.
After Width: | Height: | Size: 92 KiB |
1
数据可视化技术/实验1/resource/1.txt
Executable file
1
数据可视化技术/实验1/resource/1.txt
Executable 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
|
BIN
数据可视化技术/实验1/resource/2.png
Executable file
BIN
数据可视化技术/实验1/resource/2.png
Executable file
Binary file not shown.
After Width: | Height: | Size: 237 KiB |
2
数据可视化技术/实验1/resource/2.txt
Executable file
2
数据可视化技术/实验1/resource/2.txt
Executable file
@ -0,0 +1,2 @@
|
||||
自从1982年这本书的中文版在国内问世以来,《万历十五年》就一直畅销经久不衰,无论是历史学者还是业余爱好者,无论企业老板还是普通白领,都能从中获得一些启发和想法。也难怪,《人民的名义》里的高玉良都拿着本《万历十五年》刻苦专研。这是因为在这本书中,黄仁宇采用了一种新颖的写法,让任何人都可以几乎无障碍地去接触正史,在他的笔下,历史不再是枯燥无味的归总和罗列。这种新颖的写法,被黄仁宇本人称为“大历史观”。
|
||||
所谓“大历史观”,既不像编年体史书那样依照时间的脉络叙述一个王朝的兴衰,也不像纪传体史书那样单独介绍每个人物的一生,而是把历史剖开一个横截面,像纪录片导演穿越过去一样,把当时的一位皇帝和五位著名的大臣,以一种群像式的叙事手法缓缓展开,从中折射出16世纪中国社会的完整面貌。并且,如同管中窥豹一样,从各种细节中,观察公元1587年表面一派太平的大明朝,为何会一步一步走向衰落和灭亡。那位皇帝自然就是万历皇帝,五位大臣分别是大学生张居正和申时行,南京督察院都御史海瑞,蓟州总兵官戚继光,以及前云南姚安知府李贽。用黄仁宇的话来说,他们或是身败,或是名裂,没有一个能够功德圆满。从他们身上可以看出,那些隐藏在历史深处的症结已经开始慢慢积累,直至无可逆转。
|
BIN
数据可视化技术/实验1/resource/3.png
Executable file
BIN
数据可视化技术/实验1/resource/3.png
Executable file
Binary file not shown.
After Width: | Height: | Size: 81 KiB |
BIN
数据可视化技术/实验1/resource/4.png
Executable file
BIN
数据可视化技术/实验1/resource/4.png
Executable file
Binary file not shown.
After Width: | Height: | Size: 249 KiB |
418
数据可视化技术/实验1/task1.ipynb
Normal file
418
数据可视化技术/实验1/task1.ipynb
Normal file
File diff suppressed because one or more lines are too long
70
数据可视化技术/实验1/task2.py
Normal file
70
数据可视化技术/实验1/task2.py
Normal 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()
|
Loading…
x
Reference in New Issue
Block a user