提交 627a98e4 编写于 作者: F feilong

添加DEMO

上级 e05921c2
......@@ -19,9 +19,9 @@ python main.py
## 例子
### CSDN 问答2008-2021 月top10标签竞赛图
### DEMO CSDN 问答2008-2021 月top10标签竞赛图片段
![](./pub/tags_top10_month_ask.mp4)
### CSDN 指数趋势 2000-2021 月top10标签竞赛图
![](./demo/csdn_ask_top10_month.gif)
### DEMO CSDN 指数趋势 2000-2021 月top10标签竞赛图片段
![](./pub/trands_top10_month.mp4)
\ No newline at end of file
![](./demo/csdn_trends_top10_month.gif)
\ No newline at end of file
......@@ -32,11 +32,11 @@ def test_build_csdn_trend_top10_tag_race():
)
output = OutputMeta(
path='pub/csdn_trends_top10_month.gif',
path='pub/csdn_trends_top10_month.mp4',
title='CSDN topN指数月排行榜',
x_label='csdn.net/trends',
y_label='指数',
month_count=12
month_count=None
)
top = Top(input, output)
......
......@@ -273,7 +273,6 @@ class BarChartRace:
ax.minorticks_off()
ax.set_axisbelow(True)
ax.tick_params(length=0, labelsize=self.tick_label_size, pad=2)
# ax.set_facecolor('.97')
ax.set_title(self.title, size=self.title_size, loc='left', weight=800)
for spine in ax.spines.values():
spine.set_visible(False)
......@@ -285,7 +284,6 @@ class BarChartRace:
ax = fig.add_subplot()
fake_cols = [chr(i + 70) for i in range(self.df_values.shape[1])]
max_val = self.df_values.max().max()
# min_val = 1 if self.scale == 'log' else 0
if self.orientation == 'h':
ax.barh(fake_cols, [1] * self.df_values.shape[1])
ax.tick_params(labelrotation=0, axis='y',
......@@ -375,7 +373,6 @@ class BarChartRace:
ha='right',
color='#262525',
size=14,
# bbox=dict(facecolor='white', alpha=0.95, edgecolor='white')
)
self.ax.text(
......@@ -385,21 +382,8 @@ class BarChartRace:
ha='right',
color='#262525',
size=16,
# bbox=dict(facecolor='white', alpha=0.95, edgecolor='white')
)
# self.ax.set_yticks([]) # 隐藏Y轴标签
# if self.period_summary_func:
# values = self.df_values.iloc[i]
# ranks = self.df_ranks.iloc[i]
# text_dict = self.period_summary_func(values, ranks)
# if 'x' not in text_dict or 'y' not in text_dict or 's' not in text_dict:
# name = self.period_summary_func.__name__
# raise ValueError(f'The dictionary returned from `{name}` must contain '
# '"x", "y", and "s"')
# self.ax.text(transform=self.ax.transAxes, **text_dict)
if self.label_bars:
if self.orientation == 'h':
zipped = zip(bar_length, bar_location)
......@@ -410,53 +394,24 @@ class BarChartRace:
for x1, y1 in zipped:
xtext, ytext = self.ax.transLimits.transform((x1, y1))
# xkey = xtext
# ykey = ytext
if self.orientation == 'h':
xtext += .01
# xkey -= 0.2
text = f'{x1:,.0f}'
rotation = 0
ha = 'left'
va = 'center'
else:
ytext += .015
# ykey -= 0.2
text = f'{y1:,.0f}'
rotation = 90
ha = 'center'
va = 'bottom'
xtext, ytext = self.ax.transLimits.inverted().transform((xtext, ytext))
# xkey, ykey = self.ax.transLimits.inverted().transform((xkey, ykey))
text = self.ax.text(xtext, ytext, text, ha=ha, rotation=rotation,
fontsize=self.bar_label_size, weight=600, va=va)
# text_label = bar_keys[i]+":"+text
# self.ax.text(xkey, ykey, text_label, ha=ha, rotation=rotation,
# fontsize=self.bar_label_size, weight=600, va=va)
i += 1
# if self.perpendicular_bar_func:
# if isinstance(self.perpendicular_bar_func, str):
# val = pd.Series(bar_length).agg(self.perpendicular_bar_func)
# else:
# values = self.df_values.iloc[i]
# ranks = self.df_ranks.iloc[i]
# val = self.perpendicular_bar_func(values, ranks)
# if not self.ax.lines:
# if self.orientation == 'h':
# self.ax.axvline(val, lw=10, color='.5', zorder=.5)
# else:
# self.ax.axhline(val, lw=10, color='.5', zorder=.5)
# else:
# line = self.ax.lines[0]
# if self.orientation == 'h':
# line.set_xdata([val] * 2)
# else:
# line.set_ydata([val] * 2)
def anim_func(self, i):
print('anim_func:', i)
plt.xkcd(scale=1, length=100, randomness=2)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册