Skip to content

Commit 7dd088c

Browse files
committed
up
1 parent 2c049b1 commit 7dd088c

5 files changed

Lines changed: 12 additions & 4 deletions

File tree

Lecture/data_visual/graph_dis_box_violin.ipynb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,9 @@
446446
"source": [
447447
"下图呈现了几个特定年份的沪市综合指数的时序图 ([codes](https://github.com/arlionn/dslian/blob/main/body/codes/graph_sz_index_selected_years.ipynb)),大家可以挑选一些年份,将其收盘价的时序图与上图中对应年份的箱型图进行对比,以便更深入地理解箱型图的含义。\n",
448448
"\n",
449-
"![](./figs/sz_index_daily_return_selected_years.png)"
449+
"<!-- ![](./figs/sz_index_daily_return_selected_years.png) -->\n",
450+
"\n",
451+
"![sz_index_daily_return_selected_years](https://fig-lianxh.oss-cn-shenzhen.aliyuncs.com/sz_index_daily_return_selected_years.png){width=\"100%\"}"
450452
]
451453
},
452454
{
Binary file not shown.

docs/Lecture/data_visual/graph_dis_box_violin.html

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -809,7 +809,13 @@ <h2 data-number="14.7" class="anchored" data-anchor-id="特定年份分析"><spa
809809
</ul></li>
810810
</ul>
811811
<p>下图呈现了几个特定年份的沪市综合指数的时序图 (<a href="https://github.com/arlionn/dslian/blob/main/body/codes/graph_sz_index_selected_years.ipynb">codes</a>),大家可以挑选一些年份,将其收盘价的时序图与上图中对应年份的箱型图进行对比,以便更深入地理解箱型图的含义。</p>
812-
<p><img src="./figs/sz_index_daily_return_selected_years.png" class="img-fluid"></p>
812+
<!-- ![](./figs/sz_index_daily_return_selected_years.png) -->
813+
<div class="quarto-figure quarto-figure-center">
814+
<figure class="figure">
815+
<p><img src="https://fig-lianxh.oss-cn-shenzhen.aliyuncs.com/sz_index_daily_return_selected_years.png" class="img-fluid figure-img" style="width:100.0%"></p>
816+
<figcaption>sz_index_daily_return_selected_years</figcaption>
817+
</figure>
818+
</div>
813819
<div id="e2951591" class="cell" data-execution_count="7">
814820
<div class="sourceCode cell-code" id="cb10"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb10-1"><a href="#cb10-1" aria-hidden="true" tabindex="-1"></a></span>
815821
<span id="cb10-2"><a href="#cb10-2" aria-hidden="true" tabindex="-1"></a><span class="co"># 绘制小提琴图</span></span>

docs/search.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1431,7 +1431,7 @@
14311431
"href": "Lecture/data_visual/graph_dis_box_violin.html#特定年份分析",
14321432
"title": "14  箱型图和小提琴图",
14331433
"section": "14.7 特定年份分析:",
1434-
"text": "14.7 特定年份分析:\n\n2005 年 vs 2006 年:\n\n2005 年的箱体整体较低,中位数为负,且上胡须较短,反映当年大部分交易日处于负收益区间,市场情绪低迷。\n2006 年则大为反转,中位数跃升至零之上,箱体明显上移,收益分布更偏向正区间,显示出市场在牛市初期的积极走势。这一变化与当年“股权分置改革推进、人民币升值预期增强”等政策背景密切相关。\n\n2024 年:\n\n箱体高度极窄,即 Q75 与 Q25 非常接近,说明日收益率的四分位间距(IQR)很小,波动性低;\n同时,存在较多离群点分布在上下两侧,提示虽然整体震荡区间狭窄,但偶发性的大涨或大跌依然存在,这可能与 AI、芯片等概念股轮动剧烈,但整体指数运行平稳有关。\n\n\n下图呈现了几个特定年份的沪市综合指数的时序图 (codes),大家可以挑选一些年份,将其收盘价的时序图与上图中对应年份的箱型图进行对比,以便更深入地理解箱型图的含义。\n\n\n\n# 绘制小提琴图\nplt.figure(figsize=(6, 3))\nsns.violinplot(x='year', y='daily_return', \n data=filtered_data, palette='Set3')\nplt.grid(axis='y', linestyle='--', alpha=0.7)\nplt.show()\n\n\n\n\n\n\n\n\n\n# https://matplotlib.org/stable/gallery/statistics/boxplot_vs_violin.html\n\nimport matplotlib.pyplot as plt\nimport numpy as np\n\nfig, axs = plt.subplots(nrows=1, ncols=2, figsize=(9, 4))\n\n# Fixing random state for reproducibility\nnp.random.seed(19680801)\n\n\n# generate some random test data\nall_data = [np.random.normal(0, std, 100) for std in range(6, 10)]\n\n# plot violin plot\naxs[0].violinplot(all_data,\n showmeans=False,\n showmedians=True)\naxs[0].set_title('Violin plot')\n\n# plot box plot\naxs[1].boxplot(all_data)\naxs[1].set_title('Box plot')\n\n# adding horizontal grid lines\nfor ax in axs:\n ax.yaxis.grid(True)\n ax.set_xticks([y + 1 for y in range(len(all_data))],\n labels=['x1', 'x2', 'x3', 'x4'])\n ax.set_xlabel('Four separate samples')\n ax.set_ylabel('Observed values')\n\nplt.show()\n\n\n\n\n\n\n\n\n\n14.7.1 Add Jitter\nBy adding a stripplot, you can show all observations along with some representation of the underlying distribution.\n\nSource: Hidden Data Under Boxplot\n\n\n# libraries\nimport matplotlib.pyplot as plt\nimport numpy as np\nimport seaborn as sns\nimport pandas as pd\n \n# Dataset:\na = pd.DataFrame({ 'group' : np.repeat('A',500), 'value': np.random.normal(10, 5, 500) })\nb = pd.DataFrame({ 'group' : np.repeat('B',500), 'value': np.random.normal(13, 1.2, 500) })\nc = pd.DataFrame({ 'group' : np.repeat('B',500), 'value': np.random.normal(18, 1.2, 500) })\nd = pd.DataFrame({ 'group' : np.repeat('C',20), 'value': np.random.normal(25, 4, 20) })\ne = pd.DataFrame({ 'group' : np.repeat('D',100), 'value': np.random.uniform(12, size=100) })\ndf = pd.concat([a,b,c,d,e])\n\n# boxplot\nax = sns.boxplot(x='group', y='value', data=df)\n# add stripplot\nax = sns.stripplot(x='group', y='value', data=df, color=\"orange\", jitter=0.2, size=2.5)\n\n# add title\nplt.title(\"Boxplot with jitter\", loc=\"left\")\n\n# show the graph\nplt.show()",
1434+
"text": "14.7 特定年份分析:\n\n2005 年 vs 2006 年:\n\n2005 年的箱体整体较低,中位数为负,且上胡须较短,反映当年大部分交易日处于负收益区间,市场情绪低迷。\n2006 年则大为反转,中位数跃升至零之上,箱体明显上移,收益分布更偏向正区间,显示出市场在牛市初期的积极走势。这一变化与当年“股权分置改革推进、人民币升值预期增强”等政策背景密切相关。\n\n2024 年:\n\n箱体高度极窄,即 Q75 与 Q25 非常接近,说明日收益率的四分位间距(IQR)很小,波动性低;\n同时,存在较多离群点分布在上下两侧,提示虽然整体震荡区间狭窄,但偶发性的大涨或大跌依然存在,这可能与 AI、芯片等概念股轮动剧烈,但整体指数运行平稳有关。\n\n\n下图呈现了几个特定年份的沪市综合指数的时序图 (codes),大家可以挑选一些年份,将其收盘价的时序图与上图中对应年份的箱型图进行对比,以便更深入地理解箱型图的含义。\n\n\n\n\nsz_index_daily_return_selected_years\n\n\n\n\n# 绘制小提琴图\nplt.figure(figsize=(6, 3))\nsns.violinplot(x='year', y='daily_return', \n data=filtered_data, palette='Set3')\nplt.grid(axis='y', linestyle='--', alpha=0.7)\nplt.show()\n\n\n\n\n\n\n\n\n\n# https://matplotlib.org/stable/gallery/statistics/boxplot_vs_violin.html\n\nimport matplotlib.pyplot as plt\nimport numpy as np\n\nfig, axs = plt.subplots(nrows=1, ncols=2, figsize=(9, 4))\n\n# Fixing random state for reproducibility\nnp.random.seed(19680801)\n\n\n# generate some random test data\nall_data = [np.random.normal(0, std, 100) for std in range(6, 10)]\n\n# plot violin plot\naxs[0].violinplot(all_data,\n showmeans=False,\n showmedians=True)\naxs[0].set_title('Violin plot')\n\n# plot box plot\naxs[1].boxplot(all_data)\naxs[1].set_title('Box plot')\n\n# adding horizontal grid lines\nfor ax in axs:\n ax.yaxis.grid(True)\n ax.set_xticks([y + 1 for y in range(len(all_data))],\n labels=['x1', 'x2', 'x3', 'x4'])\n ax.set_xlabel('Four separate samples')\n ax.set_ylabel('Observed values')\n\nplt.show()\n\n\n\n\n\n\n\n\n\n14.7.1 Add Jitter\nBy adding a stripplot, you can show all observations along with some representation of the underlying distribution.\n\nSource: Hidden Data Under Boxplot\n\n\n# libraries\nimport matplotlib.pyplot as plt\nimport numpy as np\nimport seaborn as sns\nimport pandas as pd\n \n# Dataset:\na = pd.DataFrame({ 'group' : np.repeat('A',500), 'value': np.random.normal(10, 5, 500) })\nb = pd.DataFrame({ 'group' : np.repeat('B',500), 'value': np.random.normal(13, 1.2, 500) })\nc = pd.DataFrame({ 'group' : np.repeat('B',500), 'value': np.random.normal(18, 1.2, 500) })\nd = pd.DataFrame({ 'group' : np.repeat('C',20), 'value': np.random.normal(25, 4, 20) })\ne = pd.DataFrame({ 'group' : np.repeat('D',100), 'value': np.random.uniform(12, size=100) })\ndf = pd.concat([a,b,c,d,e])\n\n# boxplot\nax = sns.boxplot(x='group', y='value', data=df)\n# add stripplot\nax = sns.stripplot(x='group', y='value', data=df, color=\"orange\", jitter=0.2, size=2.5)\n\n# add title\nplt.title(\"Boxplot with jitter\", loc=\"left\")\n\n# show the graph\nplt.show()",
14351435
"crumbs": [
14361436
"**可视化**",
14371437
"<span class='chapter-number'>14</span>  <span class='chapter-title'>箱型图和小提琴图</span>"

docs/sitemap.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
</url>
7171
<url>
7272
<loc>https://lianxhcn.github.io/dsfin/Lecture/data_visual/graph_dis_box_violin.html</loc>
73-
<lastmod>2026-04-07T10:38:17.183Z</lastmod>
73+
<lastmod>2026-04-07T10:42:07.706Z</lastmod>
7474
</url>
7575
<url>
7676
<loc>https://lianxhcn.github.io/dsfin/Lecture/data_visual/graph_dis_histogram.html</loc>

0 commit comments

Comments
 (0)