纪念一下,matplotlib画出了想要的图

文章目录

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import matplotlib.pyplot as plt
import base64
import numpy as np
import pandas as pd
import os
from io import BytesIO

def survivalPlt():
grid3 = pd.read_excel(os.path.join("../", "uploadfiles", "S2_data.xlsx"), index_col=0, header=0)
# projectNames = np.array(grid3._stat_axis.values.tolist())
# projectCensors = np.array(grid3.iloc[:, 0]).reshape((1, -1))[0]
# projectLife = np.array(grid3.iloc[:, 1]).reshape((1, -1))[0]
lifes = grid3.iloc[:, 1]
stats = grid3.iloc[:, 0]
deadx = []
deady = []
livex = []
livey = []
for id,items in enumerate(lifes):
if stats[id] == 1:
deadx.append(id)
deady.append(items)
else:
livex.append(id)
livey.append(items)
figure = plt.figure(figsize=(15, 4))
ax = figure.add_subplot(111)
ax.set_frame_on(b=False)
# ax.use_sticky_edges(True)
ax.grid(True, linestyle="-.")
for key, spine in ax.spines.items():
# 'left', 'right', 'bottom', 'top'
if key == 'right' or key == 'top':
spine.set_visible(False)
ax.set_xmargin(0)
ax.set_ymargin(0)
ax.yaxis.set_label_position("right")
ax.tick_params(axis="y", direction="inout", pad=-28, labelleft="on", left=False)
ax.tick_params(axis="x", bottom=False)
ax.set_xticklabels([])
ax.scatter(deadx, deady, c="tomato")
ax.scatter(livex, livey, c="darkturquoise")
picIO = BytesIO()
plt.savefig("down.png", bbox_inches='tight', pad_inches=0.0)
plt.savefig(picIO, bbox_inches='tight', pad_inches=0.0)
data = base64.encodebytes(picIO.getvalue()).decode()
print('data:image/png;base64,' + str(data))
plt.show()

if __name__ == '__main__':
survivalPlt()

本文作者:MyTech::Author

本文链接: https://mytech.pages.dev/2020/12/17/echo_160/