Spaces:
Runtime error
Runtime error
Upload tool.py
Browse files
tool.py
CHANGED
@@ -4,7 +4,6 @@ import pandas as pd
|
|
4 |
import os
|
5 |
import random
|
6 |
from matplotlib.ticker import MaxNLocator
|
7 |
-
import matplotlib.font_manager as fm
|
8 |
#from prettytable import PrettyTable
|
9 |
#from blessed import Terminal
|
10 |
import time
|
@@ -17,11 +16,14 @@ import matplotlib.font_manager as fm
|
|
17 |
from matplotlib.lines import Line2D
|
18 |
from typing import Union, Any
|
19 |
from sklearn.linear_model import LinearRegression
|
20 |
-
plt.rcParams['font.sans-serif'] = ['Arial Unicode MS']
|
21 |
-
plt.rcParams['axes.unicode_minus'] = False
|
22 |
|
23 |
|
|
|
|
|
|
|
24 |
|
|
|
|
|
25 |
|
26 |
|
27 |
tushare_token = os.getenv('TUSHARE_TOKEN')
|
@@ -382,30 +384,30 @@ def plot_stock_data(stock_data: pd.DataFrame, ax: Optional[plt.Axes] = None, fig
|
|
382 |
|
383 |
ax.annotate(unchanged_var + ':' + str(round(start_y, 2)) + ' @' + start_x_dim, xy=(start_x_dim, start_y),
|
384 |
xytext=(start_x_dim, start_y),
|
385 |
-
textcoords='data', fontsize=
|
386 |
|
387 |
ax.annotate(unchanged_var + ':' + str(round(end_y, 2)) +' @' + end_x_dim, xy=(end_x_dim, end_y),
|
388 |
xytext=(end_x_dim, end_y),
|
389 |
-
textcoords='data', fontsize=
|
390 |
|
391 |
|
392 |
elif figure_type == 'bar':
|
393 |
ax.bar(x_dim, stock_data.iloc[:, 2], label = unchanged_var + '_' + index_name, width=0.3, color=color)
|
394 |
ax.annotate(unchanged_var + ':' + str(round(start_y, 2)) + ' @' + start_x_dim, xy=(start_x_dim, start_y),
|
395 |
xytext=(start_x_dim, start_y),
|
396 |
-
textcoords='data', fontsize=
|
397 |
|
398 |
ax.annotate(unchanged_var + ':' + str(round(end_y, 2)) + ' @' + end_x_dim, xy=(end_x_dim, end_y),
|
399 |
xytext=(end_x_dim, end_y),
|
400 |
-
textcoords='data', fontsize=
|
401 |
|
402 |
plt.xticks(x_dim,rotation=45) #
|
403 |
ax.xaxis.set_major_locator(MaxNLocator( integer=True, prune=None, nbins=100)) #
|
404 |
|
405 |
|
406 |
-
plt.xlabel(x_name)
|
407 |
-
plt.ylabel(f'{index_name}')
|
408 |
-
ax.set_title(title_name )
|
409 |
plt.legend() # 显示图例
|
410 |
fig = plt.gcf()
|
411 |
fig.set_size_inches(18, 12)
|
@@ -1759,7 +1761,7 @@ if __name__ == "__main__":
|
|
1759 |
# ------------step1 数据查询层 获取股票代码
|
1760 |
# start_last_year = get_last_year_date(start)
|
1761 |
# end_last_year = get_last_year_date(end)
|
1762 |
-
|
1763 |
# name = get_stock_name_from_code(stock_code)
|
1764 |
# print(name)
|
1765 |
# print(stock_code)
|
@@ -1795,8 +1797,8 @@ if __name__ == "__main__":
|
|
1795 |
# df_macro = get_cpi_ppi_currency_supply_data('200101','202304','cpi','nt_yoy')
|
1796 |
# df_macro = get_cpi_ppi_currency_supply_data('200101','202304','ppi','ppi_yoy')
|
1797 |
# df_macro = get_cpi_ppi_currency_supply_data('200101','202304','currency_supply','m2_yoy')
|
1798 |
-
df_gdp = get_GDP_data('2001Q1','2023Q1','gdp_yoy')
|
1799 |
-
df_gdp = predict_next_value(df_gdp, 'gdp_yoy', 4)
|
1800 |
#company_df = get_company_info('贵州茅台')
|
1801 |
#print_save_table(company_df, '贵州茅台公司信息')
|
1802 |
#fin_df = get_Financial_data_from_time_range(stock_code, '20200101', '20230526','roe')
|
|
|
4 |
import os
|
5 |
import random
|
6 |
from matplotlib.ticker import MaxNLocator
|
|
|
7 |
#from prettytable import PrettyTable
|
8 |
#from blessed import Terminal
|
9 |
import time
|
|
|
16 |
from matplotlib.lines import Line2D
|
17 |
from typing import Union, Any
|
18 |
from sklearn.linear_model import LinearRegression
|
|
|
|
|
19 |
|
20 |
|
21 |
+
# plt.rcParams['font.sans-serif'] = ['Arial Unicode MS']
|
22 |
+
# plt.rcParams['axes.unicode_minus'] = False
|
23 |
+
|
24 |
|
25 |
+
font_path = './fonts/SimHei.ttf'
|
26 |
+
font_prop = fm.FontProperties(fname=font_path)
|
27 |
|
28 |
|
29 |
tushare_token = os.getenv('TUSHARE_TOKEN')
|
|
|
384 |
|
385 |
ax.annotate(unchanged_var + ':' + str(round(start_y, 2)) + ' @' + start_x_dim, xy=(start_x_dim, start_y),
|
386 |
xytext=(start_x_dim, start_y),
|
387 |
+
textcoords='data', fontsize=14,color=color, horizontalalignment='right')
|
388 |
|
389 |
ax.annotate(unchanged_var + ':' + str(round(end_y, 2)) +' @' + end_x_dim, xy=(end_x_dim, end_y),
|
390 |
xytext=(end_x_dim, end_y),
|
391 |
+
textcoords='data', fontsize=14, color=color, horizontalalignment='left')
|
392 |
|
393 |
|
394 |
elif figure_type == 'bar':
|
395 |
ax.bar(x_dim, stock_data.iloc[:, 2], label = unchanged_var + '_' + index_name, width=0.3, color=color)
|
396 |
ax.annotate(unchanged_var + ':' + str(round(start_y, 2)) + ' @' + start_x_dim, xy=(start_x_dim, start_y),
|
397 |
xytext=(start_x_dim, start_y),
|
398 |
+
textcoords='data', fontsize=14, color=color, horizontalalignment='right')
|
399 |
|
400 |
ax.annotate(unchanged_var + ':' + str(round(end_y, 2)) + ' @' + end_x_dim, xy=(end_x_dim, end_y),
|
401 |
xytext=(end_x_dim, end_y),
|
402 |
+
textcoords='data', fontsize=14, color=color, horizontalalignment='left')
|
403 |
|
404 |
plt.xticks(x_dim,rotation=45) #
|
405 |
ax.xaxis.set_major_locator(MaxNLocator( integer=True, prune=None, nbins=100)) #
|
406 |
|
407 |
|
408 |
+
plt.xlabel(x_name, fontproperties=font_prop,fontsize=18)
|
409 |
+
plt.ylabel(f'{index_name}', fontproperties=font_prop,fontsize=16)
|
410 |
+
ax.set_title(title_name , fontproperties=font_prop,fontsize=16)
|
411 |
plt.legend() # 显示图例
|
412 |
fig = plt.gcf()
|
413 |
fig.set_size_inches(18, 12)
|
|
|
1761 |
# ------------step1 数据查询层 获取股票代码
|
1762 |
# start_last_year = get_last_year_date(start)
|
1763 |
# end_last_year = get_last_year_date(end)
|
1764 |
+
stock_code = get_stock_code(stock_name)
|
1765 |
# name = get_stock_name_from_code(stock_code)
|
1766 |
# print(name)
|
1767 |
# print(stock_code)
|
|
|
1797 |
# df_macro = get_cpi_ppi_currency_supply_data('200101','202304','cpi','nt_yoy')
|
1798 |
# df_macro = get_cpi_ppi_currency_supply_data('200101','202304','ppi','ppi_yoy')
|
1799 |
# df_macro = get_cpi_ppi_currency_supply_data('200101','202304','currency_supply','m2_yoy')
|
1800 |
+
# df_gdp = get_GDP_data('2001Q1','2023Q1','gdp_yoy')
|
1801 |
+
# df_gdp = predict_next_value(df_gdp, 'gdp_yoy', 4)
|
1802 |
#company_df = get_company_info('贵州茅台')
|
1803 |
#print_save_table(company_df, '贵州茅台公司信息')
|
1804 |
#fin_df = get_Financial_data_from_time_range(stock_code, '20200101', '20230526','roe')
|