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) 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.grid(True, linestyle="-.") for key, spine in ax.spines.items(): if key == & 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=& plt.savefig(picIO, bbox_inches=& data = base64.encodebytes(picIO.getvalue()).decode() print(& plt.show()
if __name__ == & survivalPlt()
|