def main(): st_code = input('請輸入股票代碼:') # time.strftime('%Y-%m-%d %H:%M:%S', time.localtime()) # time_now = datetime.now().strftime("%Y-%m-%d") time_30days_ago = (datetime.now() - timedelta(days=30)).strftime("%Y-%m-%d") time_90days_ago = (datetime.now() - timedelta(days=90)).strftime("%Y-%m-%d") time_1yeas_ago = (datetime.now() - timedelta(days=365)).strftime("%Y-%m-%d") while True: st_date = input('請選擇起始時間:\n0:一個月\n1:三個月\n2:一年\n') if st_date == '0': price, date, stock_name = getdata(geturl(st_code, time_30days_ago)) break if st_date == '1': price, date, stock_name = getdata(geturl(st_code, time_90days_ago)) break if st_date == '2': price, date, stock_name = getdata(geturl(st_code, time_1yeas_ago)) break else: print('\n---Error---\n請輸入正確數字,三秒後重試\n----------\n') time.sleep(3) continue # price, date, stock_name = getdata(geturl(st_code)) data = {} for p, d in zip(price, date): data[d] = p print('時間:' + d + ' ' + '成交價:' + str(p)) # 中文字體路徑 myfont = fp(fname=r'/System/Library/Fonts/STHeiti Medium.ttc') plt.plot(sorted(date), price) plt.xticks(rotation=45) if len(date) <= 30: plt.xticks(np.arange(0, len(date), 1.0)) plt.yticks(np.arange(min(price), max(price), 0.1)) elif len(date) <= 90: plt.xticks(np.arange(0, len(date), 10.0)) plt.yticks(np.arange(min(price), max(price), 0.5)) elif len(date) <= 360: plt.xticks(np.arange(0, len(date), 30.0)) plt.yticks(np.arange(min(price), max(price), 0.5)) else: plt.xticks(np.arange(0, len(date), 1.0)) plt.yticks(np.arange(min(price), max(price), 0.1)) plt.title(stock_name, fontproperties=myfont) plt.show()
def result_visualization(): my_font = fp(fname=r"C:\windows\Fonts\msyh.ttc") # 2、设置字体路径 # 设置风格 # plt.style.use('ggplot') plt.style.use('seaborn') fig = plt.figure() # 创建基础图 ax1 = fig.add_subplot(311) # 创建两个子图 ax2 = fig.add_subplot(313) ax1.plot(loss_list) # 添加折线 ax2.plot(correct_list) # 设置坐标轴标签 和 图的标题 ax1.set_xlabel('epoch') ax1.set_ylabel('loss') ax2.set_xlabel(f'epoch/{test_interval}') ax2.set_ylabel('correct') ax1.set_title('LOSS') ax2.set_title('CORRECT') # 设置文本 fig.text(x=0.13, y=0.4, s=f'最小loss:{min(loss_list)}' ' ' f'最小loss对应的epoch数:{math.ceil((loss_list.index(min(loss_list)) + 1) / math.ceil((data_length_p / BATCH_SIZE)))}' ' ' f'最后一轮loss:{loss_list[-1]}' '\n' f'最大correct:{max(correct_list)}%' ' ' f'最大correct对应的已训练epoch数:{(correct_list.index(max(correct_list)) + 1) * test_interval}' ' ' f'最后一轮correct:{correct_list[-1]}%' '\n' f'd_model={d_model} q={q} v={v} h={h} N={N} attention_size={attention_size} drop_out={dropout}' '\n' f'共耗时{round(time_cost, 2)}分钟' , FontProperties=my_font) # 保存结果图 测试不保存图(epoch少于200) if EPOCHS > 200: plt.savefig(f'result_figure/{optimizer} epoch={EPOCHS} batch={BATCH_SIZE} lr={LR} [{d_model},{q},{v},{h},{N},{attention_size},{dropout}].png') # 展示图 plt.show() print('正确率列表', correct_list) print(f'最小loss:{min(loss_list)}\r\n' f'最小loss对应的epoch数:{math.ceil((loss_list.index(min(loss_list)) + 1) / math.ceil((data_length_p / BATCH_SIZE)))}\r\n' f'最后一轮loss:{loss_list[-1]}\r\n') print(f'最大correct:{max(correct_list)}\r\n' f'最correct对应的已训练epoch数:{(correct_list.index(max(correct_list)) + 1) * test_interval}\r\n' f'最后一轮correct:{correct_list[-1]}') print(f'共耗时{round(time_cost, 2)}分钟')
def result_visualization(loss_list: list, correct_on_test: list, correct_on_train: list, test_interval: int, d_model: int, q: int, v: int, h: int, N: int, dropout: float, DATA_LEN: int, BATCH_SIZE: int, time_cost: float, EPOCH: int, draw_key: int, reslut_figure_path: str, optimizer_name: str, file_name: str, LR: float, pe: bool, mask: bool): my_font = fp(fname=r"font/simsun.ttc") # 2、设置字体路径 # 设置风格 plt.style.use('seaborn') fig = plt.figure() # 创建基础图 ax1 = fig.add_subplot(311) # 创建两个子图 ax2 = fig.add_subplot(313) ax1.plot(loss_list) # 添加折线 ax2.plot(correct_on_test, color='red', label='on Test Dataset') ax2.plot(correct_on_train, color='blue', label='on Train Dataset') # 设置坐标轴标签 和 图的标题 ax1.set_xlabel('epoch') ax1.set_ylabel('loss') ax2.set_xlabel(f'epoch/{test_interval}') ax2.set_ylabel('correct') ax1.set_title('LOSS') ax2.set_title('CORRECT') plt.legend(loc='best') # 设置文本 fig.text( x=0.13, y=0.4, s=f'最小loss:{min(loss_list)}' ' ' f'最小loss对应的epoch数:{math.ceil((loss_list.index(min(loss_list)) + 1) / math.ceil((DATA_LEN / BATCH_SIZE)))}' ' ' f'最后一轮loss:{loss_list[-1]}' '\n' f'最大correct:测试集:{max(correct_on_test)}% 训练集:{max(correct_on_train)}%' ' ' f'最大correct对应的已训练epoch数:{(correct_on_test.index(max(correct_on_test)) + 1) * test_interval}' ' ' f'最后一轮correct:{correct_on_test[-1]}%' '\n' f'd_model={d_model} q={q} v={v} h={h} N={N} drop_out={dropout}' '\n' f'共耗时{round(time_cost, 2)}分钟', FontProperties=my_font) # 保存结果图 测试不保存图(epoch少于draw_key) if EPOCH >= draw_key: plt.savefig( f'{reslut_figure_path}/{file_name} {max(correct_on_test)}% {optimizer_name} epoch={EPOCH} batch={BATCH_SIZE} lr={LR} pe={pe} mask={mask} [{d_model},{q},{v},{h},{N},{dropout}].png' ) # 展示图 plt.show() print('正确率列表', correct_on_test) print( f'最小loss:{min(loss_list)}\r\n' f'最小loss对应的epoch数:{math.ceil((loss_list.index(min(loss_list)) + 1) / math.ceil((DATA_LEN / BATCH_SIZE)))}\r\n' f'最后一轮loss:{loss_list[-1]}\r\n') print( f'最大correct:测试集:{max(correct_on_test)}\t 训练集:{max(correct_on_train)}\r\n' f'最correct对应的已训练epoch数:{(correct_on_test.index(max(correct_on_test)) + 1) * test_interval}\r\n' f'最后一轮correct:{correct_on_test[-1]}') print(f'共耗时{round(time_cost, 2)}分钟')
#In v2, I tweaked the way I was making the plot in matplot lib to try to make it easy to create a legend #In v3, Fixed bug related to reads with doubly aligned bases. Only counted the left most alignments # **** Known issue related with mutations (I think) near breakpoints, that lead to unaligned, internal bases. This could be accounted for, but it's unclear whether bases should be added to left or right. #In v3.1, Slightly changed the way the sizes for the legend circles is calculated to avoid non-integers from __future__ import division import sys, optparse, os, pysam, math import numpy as np from scipy.stats import gaussian_kde #For plotting import matplotlib matplotlib.use('PDF') import matplotlib.pyplot as plt from matplotlib.font_manager import FontProperties as fp fontP = fp() def main(): #To parse command line usage = "usage: %prog [options]" p = optparse.OptionParser(usage) p.add_option('-b', '--bam', help='input sam or bam file. [None, REQ]') p.add_option('-o', '--out', default="chimerareads", help='String to add to bam names for output. [chimerareads]') p.add_option( '-m',
def result_visualization(): my_font = fp(fname=r"/content/drive/MyDrive/font/SIMSUN.TTC") # 2、设置字体路径 # 设置风格 # plt.style.use('ggplot') plt.style.use('seaborn') fig = plt.figure() # 创建基础图 ax1 = fig.add_subplot(311) # 创建两个子图 ax2 = fig.add_subplot(313) ax1.plot(loss_list) # 添加折线 ax2.plot(correct_list, color='red', label='on Test Dataset') ax2.plot(correct_list_ontrain, color='blue', label='on Train Dataset') # 设置坐标轴标签 和 图的标题 ax1.set_xlabel('epoch') ax1.set_ylabel('loss') ax2.set_xlabel(f'epoch/{test_interval}') ax2.set_ylabel('correct') ax1.set_title('LOSS') ax2.set_title('CORRECT') plt.legend(loc='best') # 设置文本 fig.text( x=0.13, y=0.4, s=f'最小loss:{min(loss_list)}' ' ' f'最小loss对应的epoch数:{math.ceil((loss_list.index(min(loss_list)) + 1) / math.ceil((data_length_p / BATCH_SIZE)))}' ' ' f'最后一轮loss:{loss_list[-1]}' '\n' f'最大correct:{max(correct_list)}%' ' ' f'最大correct对应的已训练epoch数:{(correct_list.index(max(correct_list)) + 1) * test_interval}' ' ' f'最后一轮correct:{correct_list[-1]}%' '\n' f'd_model={d_model} q={q} v={v} h={h} N={N} drop_out={dropout}' '\n' f'共耗时{round(time_cost, 2)}分钟', FontProperties=my_font) # 保存结果图 测试不保存图(epoch少于draw_key) if EPOCHS >= draw_key: plt.savefig( f'{reslut_figure_path}/{file_name} {max(correct_list)}% {optimizer_p} epoch={EPOCHS} batch={BATCH_SIZE} lr={LR} [{d_model},{q},{v},{h},{N},{dropout}].png' ) # 展示图 plt.show() print('正确率列表', correct_list) print( f'最小loss:{min(loss_list)}\r\n' f'最小loss对应的epoch数:{math.ceil((loss_list.index(min(loss_list)) + 1) / math.ceil((data_length_p / BATCH_SIZE)))}\r\n' f'最后一轮loss:{loss_list[-1]}\r\n') print( f'最大correct:{max(correct_list)}\r\n' f'最correct对应的已训练epoch数:{(correct_list.index(max(correct_list)) + 1) * test_interval}\r\n' f'最后一轮correct:{correct_list[-1]}') print(f'共耗时{round(time_cost, 2)}分钟')
n1 = len(x1) n2 = len(x2) n3 = len(x3) out_str1 = '$R^2$ = {:3.2f}'.format(rsq1) + '\nN = {:,}'.format(n1) out_str2 = '$R^2$ = {:3.2f}'.format(rsq2) + '\nN = {:,}'.format(n2) out_str3 = '$R^2$ = {:3.2f}'.format(rsq3) + '\nN = {:,}'.format(n3) # x1, y1, z1 = sc_plot(x1, y1, density_bins) # x2, y2, z2 = sc_plot(x2, y2, density_bins) # x3, y3, z3 = sc_plot(x3, y3, density_bins) end_p = np.array([0, 1]) font = fp() font.set_size('small') rect = patches.Rectangle((0.65 * xlim[1], 0.98 * ylim[1]), 0.33 * xlim[1], -0.18 * ylim[1], linewidth=1, fill=True, alpha=0.9, edgecolor='black', facecolor='whitesmoke', zorder=2) ax1.imshow(heatmap_1, extent=extent_1, origin='lower',
def result_visualization(loss_list: list, correct_on_test: list, correct_on_train: list, test_interval: int, d_model: int, dropout: float, BATCH_SIZE: int, EPOCH: int, result_figure_path: str, LR: float): my_font = fp(fname=r"font/simsun.ttc") # 2、设置字体路径 # 设置风格 plt.style.use('seaborn') fig = plt.figure() # 创建基础图 ax1 = fig.add_subplot(311) # 创建两个子图 ax2 = fig.add_subplot(313) ax1.plot(loss_list) # 添加折线 ax2.plot(correct_on_test, color='red', label='on Test Dataset') ax2.plot(correct_on_train, color='blue', label='on Train Dataset') # 设置坐标轴标签 和 图的标题 ax1.set_xlabel('epoch') ax1.set_ylabel('loss') ax2.set_xlabel(f'epoch/{test_interval}') ax2.set_ylabel('correct') ax1.set_title('LOSS') ax2.set_title('CORRECT') plt.legend(loc='best') # 设置文本 fig.text( x=0.13, y=0.4, s=f'最小loss:{min(loss_list)}' ' ' f'最后一轮loss:{loss_list[-1]}' '\n' f'最大correct:测试集:{max(correct_on_test)}% 训练集:{max(correct_on_train)}%' ' ' f'最大correct对应的已训练epoch数:{(correct_on_test.index(max(correct_on_test)) + 1) * test_interval}' ' ' f'最后一轮correct:{correct_on_test[-1]}%' '\n' f'd_model={d_model} drop_out={dropout}' '\n', FontProperties=my_font) # 保存结果图 测试不保存图(epoch少于draw_key) plt.savefig( f'{result_figure_path}/{max(correct_on_test)}% epoch={EPOCH} batch={BATCH_SIZE} lr={LR} d_model={d_model} dropout={dropout}.png' ) # 展示图 plt.show() print('正确率列表', correct_on_test) print(f'最小loss:{min(loss_list)}\r\n' f'最后一轮loss:{loss_list[-1]}\r\n') print( f'最大correct:测试集:{max(correct_on_test)}\t 训练集:{max(correct_on_train)}\r\n' f'最correct对应的已训练epoch数:{(correct_on_test.index(max(correct_on_test)) + 1) * test_interval}\r\n' f'最后一轮correct:{correct_on_test[-1]}')
xData, yData = np.meshgrid(x, y) fig = plt.figure() ax = fig.add_subplot(111) levels = np.linspace(0, 0.01, 11) # plot both the 2D data and the contours ax.imshow(zData, origin="lower", cmap=plt.get_cmap("Reds"), extent=[0, 10, 0, 10]) C = ax.contour(xData, yData, zData, levels, cmap=plt.get_cmap("Blues"), linewidths=(2)) fig.colorbar(C) # find highest peak and coordinates coord = np.unravel_index(zData.argmax(), zData.shape) # returns (y index, x index) xp, yp = x[coord[1]], y[coord[0]] # save some space from matplotlib.font_manager import FontProperties as fp ax.annotate("Best Peak", xy=(xp, yp), xycoords="data", xytext=(-70, -50), textcoords="offset points", arrowprops=dict(arrowstyle="->"), fontproperties=fp(size=16, weight="bold") ) decorateAxes(ax) makeOutputs(fig, "2D_contour") fig.set_size_inches(8, 8) plt.show()