Skip to content

Instantly share code, notes, and snippets.

@yssymmt
Created August 12, 2023 13:57
Show Gist options
  • Save yssymmt/fd1f74c979e56261e9df7b40304af88b to your computer and use it in GitHub Desktop.
Save yssymmt/fd1f74c979e56261e9df7b40304af88b to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"id": "7f93cf53-9cdc-4e4f-aec6-5b22547202b1",
"metadata": {},
"source": [
"### 箱ひげ図を描いてみよう Altair編"
]
},
{
"cell_type": "markdown",
"id": "8aa794ee-ffa8-4a53-90a2-79fc09aed8a6",
"metadata": {},
"source": [
"#### ライブラリの読み込み"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "bdd54c89-205c-47b3-acdb-9b8e84166178",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"import pandas as pd\n",
"import altair as alt "
]
},
{
"cell_type": "markdown",
"id": "73917599-d3f2-44a7-ab68-68394ec3cd11",
"metadata": {},
"source": [
"#### ファイルの読み込み"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "89a44ef5-d3d3-4fba-b5ed-9425422de3c8",
"metadata": {
"tags": []
},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>色</th>\n",
" <th>変数名</th>\n",
" <th>最小値</th>\n",
" <th>第1四分位</th>\n",
" <th>第2四分位</th>\n",
" <th>第3四分位</th>\n",
" <th>最大値</th>\n",
" <th>平均値</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>a</td>\n",
" <td>変数1</td>\n",
" <td>4</td>\n",
" <td>6</td>\n",
" <td>19</td>\n",
" <td>20</td>\n",
" <td>33</td>\n",
" <td>16.6</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>b</td>\n",
" <td>変数2</td>\n",
" <td>4</td>\n",
" <td>7</td>\n",
" <td>17</td>\n",
" <td>25</td>\n",
" <td>29</td>\n",
" <td>16.8</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>a</td>\n",
" <td>変数3</td>\n",
" <td>3</td>\n",
" <td>10</td>\n",
" <td>12</td>\n",
" <td>24</td>\n",
" <td>28</td>\n",
" <td>15.8</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>b</td>\n",
" <td>変数4</td>\n",
" <td>3</td>\n",
" <td>6</td>\n",
" <td>16</td>\n",
" <td>26</td>\n",
" <td>28</td>\n",
" <td>16.2</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>a</td>\n",
" <td>変数5</td>\n",
" <td>1</td>\n",
" <td>6</td>\n",
" <td>15</td>\n",
" <td>23</td>\n",
" <td>29</td>\n",
" <td>15.4</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>b</td>\n",
" <td>変数6</td>\n",
" <td>5</td>\n",
" <td>10</td>\n",
" <td>16</td>\n",
" <td>22</td>\n",
" <td>30</td>\n",
" <td>17.4</td>\n",
" </tr>\n",
" <tr>\n",
" <th>6</th>\n",
" <td>a</td>\n",
" <td>変数7</td>\n",
" <td>1</td>\n",
" <td>9</td>\n",
" <td>15</td>\n",
" <td>23</td>\n",
" <td>33</td>\n",
" <td>16.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7</th>\n",
" <td>b</td>\n",
" <td>変数8</td>\n",
" <td>1</td>\n",
" <td>10</td>\n",
" <td>19</td>\n",
" <td>22</td>\n",
" <td>31</td>\n",
" <td>16.6</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>a</td>\n",
" <td>変数9</td>\n",
" <td>2</td>\n",
" <td>7</td>\n",
" <td>19</td>\n",
" <td>20</td>\n",
" <td>29</td>\n",
" <td>15.4</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" 色 変数名 最小値 第1四分位 第2四分位 第3四分位 最大値 平均値\n",
"0 a 変数1 4 6 19 20 33 16.6\n",
"1 b 変数2 4 7 17 25 29 16.8\n",
"2 a 変数3 3 10 12 24 28 15.8\n",
"3 b 変数4 3 6 16 26 28 16.2\n",
"4 a 変数5 1 6 15 23 29 15.4\n",
"5 b 変数6 5 10 16 22 30 17.4\n",
"6 a 変数7 1 9 15 23 33 16.0\n",
"7 b 変数8 1 10 19 22 31 16.6\n",
"8 a 変数9 2 7 19 20 29 15.4"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df_box = pd.read_csv('boxplot_dat.csv')\n",
"df_box"
]
},
{
"cell_type": "markdown",
"id": "671a1e3d-e3f0-4137-8e80-9a91738f77c1",
"metadata": {},
"source": [
"#### 横に表示する"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "358e0b7f-427a-4b1c-8831-942a41aed827",
"metadata": {
"tags": []
},
"outputs": [
{
"data": {
"text/html": [
"\n",
"<style>\n",
" #altair-viz-24755886f92e48eaa31d86ac1434a166.vega-embed {\n",
" width: 100%;\n",
" display: flex;\n",
" }\n",
"\n",
" #altair-viz-24755886f92e48eaa31d86ac1434a166.vega-embed details,\n",
" #altair-viz-24755886f92e48eaa31d86ac1434a166.vega-embed details summary {\n",
" position: relative;\n",
" }\n",
"</style>\n",
"<div id=\"altair-viz-24755886f92e48eaa31d86ac1434a166\"></div>\n",
"<script type=\"text/javascript\">\n",
" var VEGA_DEBUG = (typeof VEGA_DEBUG == \"undefined\") ? {} : VEGA_DEBUG;\n",
" (function(spec, embedOpt){\n",
" let outputDiv = document.currentScript.previousElementSibling;\n",
" if (outputDiv.id !== \"altair-viz-24755886f92e48eaa31d86ac1434a166\") {\n",
" outputDiv = document.getElementById(\"altair-viz-24755886f92e48eaa31d86ac1434a166\");\n",
" }\n",
" const paths = {\n",
" \"vega\": \"https://cdn.jsdelivr.net/npm/vega@5?noext\",\n",
" \"vega-lib\": \"https://cdn.jsdelivr.net/npm/vega-lib?noext\",\n",
" \"vega-lite\": \"https://cdn.jsdelivr.net/npm/vega-lite@5.8.0?noext\",\n",
" \"vega-embed\": \"https://cdn.jsdelivr.net/npm/vega-embed@6?noext\",\n",
" };\n",
"\n",
" function maybeLoadScript(lib, version) {\n",
" var key = `${lib.replace(\"-\", \"\")}_version`;\n",
" return (VEGA_DEBUG[key] == version) ?\n",
" Promise.resolve(paths[lib]) :\n",
" new Promise(function(resolve, reject) {\n",
" var s = document.createElement('script');\n",
" document.getElementsByTagName(\"head\")[0].appendChild(s);\n",
" s.async = true;\n",
" s.onload = () => {\n",
" VEGA_DEBUG[key] = version;\n",
" return resolve(paths[lib]);\n",
" };\n",
" s.onerror = () => reject(`Error loading script: ${paths[lib]}`);\n",
" s.src = paths[lib];\n",
" });\n",
" }\n",
"\n",
" function showError(err) {\n",
" outputDiv.innerHTML = `<div class=\"error\" style=\"color:red;\">${err}</div>`;\n",
" throw err;\n",
" }\n",
"\n",
" function displayChart(vegaEmbed) {\n",
" vegaEmbed(outputDiv, spec, embedOpt)\n",
" .catch(err => showError(`Javascript Error: ${err.message}<br>This usually means there's a typo in your chart specification. See the javascript console for the full traceback.`));\n",
" }\n",
"\n",
" if(typeof define === \"function\" && define.amd) {\n",
" requirejs.config({paths});\n",
" require([\"vega-embed\"], displayChart, err => showError(`Error loading script: ${err.message}`));\n",
" } else {\n",
" maybeLoadScript(\"vega\", \"5\")\n",
" .then(() => maybeLoadScript(\"vega-lite\", \"5.8.0\"))\n",
" .then(() => maybeLoadScript(\"vega-embed\", \"6\"))\n",
" .catch(showError)\n",
" .then(() => displayChart(vegaEmbed));\n",
" }\n",
" })({\"config\": {\"view\": {\"continuousWidth\": 300, \"continuousHeight\": 300}}, \"layer\": [{\"mark\": {\"type\": \"rule\", \"color\": \"#A6A6A6\", \"opacity\": 0.8, \"size\": 3}, \"encoding\": {\"x\": {\"field\": \"\\u5909\\u6570\\u540d\", \"title\": \"\\u5909\\u6570\\u540d\", \"type\": \"nominal\"}, \"y\": {\"field\": \"\\u6700\\u5c0f\\u5024\", \"title\": \"\\u5024 (\\u9ed2:\\u5e73\\u5747\\u5024 | \\u767d:\\u4e2d\\u592e\\u5024)\", \"type\": \"quantitative\"}, \"y2\": {\"field\": \"\\u6700\\u5927\\u5024\"}}, \"title\": \"\\u7bb1\\u3072\\u3052\\u56f3\"}, {\"mark\": {\"type\": \"bar\", \"color\": \"#00A4A0\", \"opacity\": 0.5, \"size\": 30}, \"encoding\": {\"x\": {\"field\": \"\\u5909\\u6570\\u540d\", \"title\": \"\\u5909\\u6570\\u540d\", \"type\": \"nominal\"}, \"y\": {\"field\": \"\\u7b2c1\\u56db\\u5206\\u4f4d\", \"type\": \"quantitative\"}, \"y2\": {\"field\": \"\\u7b2c3\\u56db\\u5206\\u4f4d\"}}}, {\"mark\": {\"type\": \"tick\", \"color\": \"#A6A6A6\", \"opacity\": 0.8, \"size\": 20, \"thickness\": 3}, \"encoding\": {\"x\": {\"field\": \"\\u5909\\u6570\\u540d\", \"title\": \"\\u5909\\u6570\\u540d\", \"type\": \"nominal\"}, \"y\": {\"field\": \"\\u6700\\u5c0f\\u5024\", \"type\": \"quantitative\"}}}, {\"mark\": {\"type\": \"tick\", \"color\": \"#A6A6A6\", \"opacity\": 0.8, \"size\": 20, \"thickness\": 3}, \"encoding\": {\"x\": {\"field\": \"\\u5909\\u6570\\u540d\", \"title\": \"\\u5909\\u6570\\u540d\", \"type\": \"nominal\"}, \"y\": {\"field\": \"\\u6700\\u5927\\u5024\", \"type\": \"quantitative\"}}}, {\"mark\": {\"type\": \"tick\", \"color\": \"#000000\", \"opacity\": 0.5, \"size\": 20, \"thickness\": 3}, \"encoding\": {\"x\": {\"field\": \"\\u5909\\u6570\\u540d\", \"title\": \"\\u5909\\u6570\\u540d\", \"type\": \"nominal\"}, \"y\": {\"field\": \"\\u5e73\\u5747\\u5024\", \"type\": \"quantitative\"}}}, {\"mark\": {\"type\": \"tick\", \"color\": \"#FFFFFF\", \"opacity\": 1, \"size\": 20, \"thickness\": 3}, \"encoding\": {\"x\": {\"field\": \"\\u5909\\u6570\\u540d\", \"title\": \"\\u5909\\u6570\\u540d\", \"type\": \"nominal\"}, \"y\": {\"field\": \"\\u7b2c2\\u56db\\u5206\\u4f4d\", \"type\": \"quantitative\"}}}], \"data\": {\"name\": \"data-4e6a8369c4777dc759b296d10858d844\"}, \"height\": 400, \"width\": 600, \"$schema\": \"https://vega.github.io/schema/vega-lite/v5.8.0.json\", \"datasets\": {\"data-4e6a8369c4777dc759b296d10858d844\": [{\"\\u8272\": \"a\", \"\\u5909\\u6570\\u540d\": \"\\u5909\\u65701\", \"\\u6700\\u5c0f\\u5024\": 4, \"\\u7b2c1\\u56db\\u5206\\u4f4d\": 6, \"\\u7b2c2\\u56db\\u5206\\u4f4d\": 19, \"\\u7b2c3\\u56db\\u5206\\u4f4d\": 20, \"\\u6700\\u5927\\u5024\": 33, \"\\u5e73\\u5747\\u5024\": 16.6}, {\"\\u8272\": \"b\", \"\\u5909\\u6570\\u540d\": \"\\u5909\\u65702\", \"\\u6700\\u5c0f\\u5024\": 4, \"\\u7b2c1\\u56db\\u5206\\u4f4d\": 7, \"\\u7b2c2\\u56db\\u5206\\u4f4d\": 17, \"\\u7b2c3\\u56db\\u5206\\u4f4d\": 25, \"\\u6700\\u5927\\u5024\": 29, \"\\u5e73\\u5747\\u5024\": 16.8}, {\"\\u8272\": \"a\", \"\\u5909\\u6570\\u540d\": \"\\u5909\\u65703\", \"\\u6700\\u5c0f\\u5024\": 3, \"\\u7b2c1\\u56db\\u5206\\u4f4d\": 10, \"\\u7b2c2\\u56db\\u5206\\u4f4d\": 12, \"\\u7b2c3\\u56db\\u5206\\u4f4d\": 24, \"\\u6700\\u5927\\u5024\": 28, \"\\u5e73\\u5747\\u5024\": 15.8}, {\"\\u8272\": \"b\", \"\\u5909\\u6570\\u540d\": \"\\u5909\\u65704\", \"\\u6700\\u5c0f\\u5024\": 3, \"\\u7b2c1\\u56db\\u5206\\u4f4d\": 6, \"\\u7b2c2\\u56db\\u5206\\u4f4d\": 16, \"\\u7b2c3\\u56db\\u5206\\u4f4d\": 26, \"\\u6700\\u5927\\u5024\": 28, \"\\u5e73\\u5747\\u5024\": 16.2}, {\"\\u8272\": \"a\", \"\\u5909\\u6570\\u540d\": \"\\u5909\\u65705\", \"\\u6700\\u5c0f\\u5024\": 1, \"\\u7b2c1\\u56db\\u5206\\u4f4d\": 6, \"\\u7b2c2\\u56db\\u5206\\u4f4d\": 15, \"\\u7b2c3\\u56db\\u5206\\u4f4d\": 23, \"\\u6700\\u5927\\u5024\": 29, \"\\u5e73\\u5747\\u5024\": 15.4}, {\"\\u8272\": \"b\", \"\\u5909\\u6570\\u540d\": \"\\u5909\\u65706\", \"\\u6700\\u5c0f\\u5024\": 5, \"\\u7b2c1\\u56db\\u5206\\u4f4d\": 10, \"\\u7b2c2\\u56db\\u5206\\u4f4d\": 16, \"\\u7b2c3\\u56db\\u5206\\u4f4d\": 22, \"\\u6700\\u5927\\u5024\": 30, \"\\u5e73\\u5747\\u5024\": 17.4}, {\"\\u8272\": \"a\", \"\\u5909\\u6570\\u540d\": \"\\u5909\\u65707\", \"\\u6700\\u5c0f\\u5024\": 1, \"\\u7b2c1\\u56db\\u5206\\u4f4d\": 9, \"\\u7b2c2\\u56db\\u5206\\u4f4d\": 15, \"\\u7b2c3\\u56db\\u5206\\u4f4d\": 23, \"\\u6700\\u5927\\u5024\": 33, \"\\u5e73\\u5747\\u5024\": 16.0}, {\"\\u8272\": \"b\", \"\\u5909\\u6570\\u540d\": \"\\u5909\\u65708\", \"\\u6700\\u5c0f\\u5024\": 1, \"\\u7b2c1\\u56db\\u5206\\u4f4d\": 10, \"\\u7b2c2\\u56db\\u5206\\u4f4d\": 19, \"\\u7b2c3\\u56db\\u5206\\u4f4d\": 22, \"\\u6700\\u5927\\u5024\": 31, \"\\u5e73\\u5747\\u5024\": 16.6}, {\"\\u8272\": \"a\", \"\\u5909\\u6570\\u540d\": \"\\u5909\\u65709\", \"\\u6700\\u5c0f\\u5024\": 2, \"\\u7b2c1\\u56db\\u5206\\u4f4d\": 7, \"\\u7b2c2\\u56db\\u5206\\u4f4d\": 19, \"\\u7b2c3\\u56db\\u5206\\u4f4d\": 20, \"\\u6700\\u5927\\u5024\": 29, \"\\u5e73\\u5747\\u5024\": 15.4}]}}, {\"mode\": \"vega-lite\"});\n",
"</script>"
],
"text/plain": [
"alt.LayerChart(...)"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"box_plot1 = alt.Chart(df_box).mark_rule(\n",
" color='#A6A6A6', \n",
" opacity=0.8, \n",
" size=3 \n",
").encode(\n",
" x=alt.X('変数名:N', title='変数名'), \n",
" y=alt.Y('最小値:Q', title='値 (黒:平均値 | 白:中央値)'), \n",
" y2=alt.Y2('最大値:Q')\n",
").properties(\n",
" width=600, \n",
" height=400,\n",
" title='箱ひげ図' \n",
") \n",
"\n",
"box_plot2 = alt.Chart(df_box).mark_bar(\n",
" color='#00A4A0', \n",
" opacity=0.5, \n",
" size=30 \n",
").encode(\n",
" x=alt.X('変数名:N', title='変数名'), \n",
" y=alt.Y('第1四分位:Q'), \n",
" y2=alt.Y2('第3四分位:Q')\n",
")\n",
"\n",
"box_plot3 = alt.Chart(df_box).mark_tick(\n",
" color='#A6A6A6', \n",
" opacity=0.8, \n",
" size=20, \n",
" thickness=3\n",
").encode(\n",
" x=alt.X('変数名:N', title='変数名'), \n",
" y=alt.Y('最小値:Q') \n",
")\n",
"\n",
"box_plot4 = alt.Chart(df_box).mark_tick(\n",
" color='#A6A6A6', \n",
" opacity=0.8, \n",
" size=20, \n",
" thickness=3\n",
").encode(\n",
" x=alt.X('変数名:N', title='変数名'), \n",
" y=alt.Y('最大値:Q')\n",
")\n",
"\n",
"box_plot5 = alt.Chart(df_box).mark_tick(\n",
" color='#000000', \n",
" opacity=0.5, \n",
" size=20, \n",
" thickness=3\n",
").encode(\n",
" x=alt.X('変数名:N', title='変数名'), \n",
" y=alt.Y('平均値:Q')\n",
")\n",
"\n",
"box_plot6 = alt.Chart(df_box).mark_tick(\n",
" color='#FFFFFF', \n",
" opacity=1, \n",
" size=20, \n",
" thickness=3\n",
").encode(\n",
" x=alt.X('変数名:N', title='変数名'), \n",
" y=alt.Y('第2四分位:Q')\n",
")\n",
"\n",
"box_plot1 + box_plot2 + box_plot3 + box_plot4 + box_plot5 + box_plot6 "
]
},
{
"cell_type": "markdown",
"id": "276e68b1-8327-4bb7-b699-adad6f00aa06",
"metadata": {},
"source": [
"#### 縦に表示する"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "f6a18958-be72-465d-b284-4db248a38e02",
"metadata": {
"tags": []
},
"outputs": [
{
"data": {
"text/html": [
"\n",
"<style>\n",
" #altair-viz-6e73d5340c594ac9be03e33c24cdb52c.vega-embed {\n",
" width: 100%;\n",
" display: flex;\n",
" }\n",
"\n",
" #altair-viz-6e73d5340c594ac9be03e33c24cdb52c.vega-embed details,\n",
" #altair-viz-6e73d5340c594ac9be03e33c24cdb52c.vega-embed details summary {\n",
" position: relative;\n",
" }\n",
"</style>\n",
"<div id=\"altair-viz-6e73d5340c594ac9be03e33c24cdb52c\"></div>\n",
"<script type=\"text/javascript\">\n",
" var VEGA_DEBUG = (typeof VEGA_DEBUG == \"undefined\") ? {} : VEGA_DEBUG;\n",
" (function(spec, embedOpt){\n",
" let outputDiv = document.currentScript.previousElementSibling;\n",
" if (outputDiv.id !== \"altair-viz-6e73d5340c594ac9be03e33c24cdb52c\") {\n",
" outputDiv = document.getElementById(\"altair-viz-6e73d5340c594ac9be03e33c24cdb52c\");\n",
" }\n",
" const paths = {\n",
" \"vega\": \"https://cdn.jsdelivr.net/npm/vega@5?noext\",\n",
" \"vega-lib\": \"https://cdn.jsdelivr.net/npm/vega-lib?noext\",\n",
" \"vega-lite\": \"https://cdn.jsdelivr.net/npm/vega-lite@5.8.0?noext\",\n",
" \"vega-embed\": \"https://cdn.jsdelivr.net/npm/vega-embed@6?noext\",\n",
" };\n",
"\n",
" function maybeLoadScript(lib, version) {\n",
" var key = `${lib.replace(\"-\", \"\")}_version`;\n",
" return (VEGA_DEBUG[key] == version) ?\n",
" Promise.resolve(paths[lib]) :\n",
" new Promise(function(resolve, reject) {\n",
" var s = document.createElement('script');\n",
" document.getElementsByTagName(\"head\")[0].appendChild(s);\n",
" s.async = true;\n",
" s.onload = () => {\n",
" VEGA_DEBUG[key] = version;\n",
" return resolve(paths[lib]);\n",
" };\n",
" s.onerror = () => reject(`Error loading script: ${paths[lib]}`);\n",
" s.src = paths[lib];\n",
" });\n",
" }\n",
"\n",
" function showError(err) {\n",
" outputDiv.innerHTML = `<div class=\"error\" style=\"color:red;\">${err}</div>`;\n",
" throw err;\n",
" }\n",
"\n",
" function displayChart(vegaEmbed) {\n",
" vegaEmbed(outputDiv, spec, embedOpt)\n",
" .catch(err => showError(`Javascript Error: ${err.message}<br>This usually means there's a typo in your chart specification. See the javascript console for the full traceback.`));\n",
" }\n",
"\n",
" if(typeof define === \"function\" && define.amd) {\n",
" requirejs.config({paths});\n",
" require([\"vega-embed\"], displayChart, err => showError(`Error loading script: ${err.message}`));\n",
" } else {\n",
" maybeLoadScript(\"vega\", \"5\")\n",
" .then(() => maybeLoadScript(\"vega-lite\", \"5.8.0\"))\n",
" .then(() => maybeLoadScript(\"vega-embed\", \"6\"))\n",
" .catch(showError)\n",
" .then(() => displayChart(vegaEmbed));\n",
" }\n",
" })({\"config\": {\"view\": {\"continuousWidth\": 300, \"continuousHeight\": 300}}, \"layer\": [{\"mark\": {\"type\": \"rule\", \"color\": \"#A6A6A6\", \"opacity\": 0.8, \"size\": 3}, \"encoding\": {\"x\": {\"field\": \"\\u6700\\u5c0f\\u5024\", \"title\": \"\\u5024 (\\u9ed2:\\u5e73\\u5747\\u5024 | \\u767d:\\u4e2d\\u592e\\u5024)\", \"type\": \"quantitative\"}, \"x2\": {\"field\": \"\\u6700\\u5927\\u5024\"}, \"y\": {\"field\": \"\\u5909\\u6570\\u540d\", \"title\": \"\\u5909\\u6570\\u540d\", \"type\": \"nominal\"}}, \"title\": \"\\u7bb1\\u3072\\u3052\\u56f3\"}, {\"mark\": {\"type\": \"bar\", \"color\": \"#00A4A0\", \"opacity\": 0.5, \"size\": 30}, \"encoding\": {\"x\": {\"field\": \"\\u7b2c1\\u56db\\u5206\\u4f4d\", \"type\": \"quantitative\"}, \"x2\": {\"field\": \"\\u7b2c3\\u56db\\u5206\\u4f4d\"}, \"y\": {\"field\": \"\\u5909\\u6570\\u540d\", \"title\": \"\\u5909\\u6570\\u540d\", \"type\": \"nominal\"}}}, {\"mark\": {\"type\": \"tick\", \"color\": \"#A6A6A6\", \"opacity\": 0.8, \"size\": 20, \"thickness\": 3}, \"encoding\": {\"x\": {\"field\": \"\\u6700\\u5c0f\\u5024\", \"type\": \"quantitative\"}, \"y\": {\"field\": \"\\u5909\\u6570\\u540d\", \"title\": \"\\u5909\\u6570\\u540d\", \"type\": \"nominal\"}}}, {\"mark\": {\"type\": \"tick\", \"color\": \"#A6A6A6\", \"opacity\": 0.8, \"size\": 20, \"thickness\": 3}, \"encoding\": {\"x\": {\"field\": \"\\u6700\\u5927\\u5024\", \"type\": \"quantitative\"}, \"y\": {\"field\": \"\\u5909\\u6570\\u540d\", \"title\": \"\\u5909\\u6570\\u540d\", \"type\": \"nominal\"}}}, {\"mark\": {\"type\": \"tick\", \"color\": \"#000000\", \"opacity\": 0.5, \"size\": 20, \"thickness\": 3}, \"encoding\": {\"x\": {\"field\": \"\\u5e73\\u5747\\u5024\", \"type\": \"quantitative\"}, \"y\": {\"field\": \"\\u5909\\u6570\\u540d\", \"title\": \"\\u5909\\u6570\\u540d\", \"type\": \"nominal\"}}}, {\"mark\": {\"type\": \"tick\", \"color\": \"#FFFFFF\", \"opacity\": 1, \"size\": 20, \"thickness\": 3}, \"encoding\": {\"x\": {\"field\": \"\\u7b2c2\\u56db\\u5206\\u4f4d\", \"type\": \"quantitative\"}, \"y\": {\"field\": \"\\u5909\\u6570\\u540d\", \"title\": \"\\u5909\\u6570\\u540d\", \"type\": \"nominal\"}}}], \"data\": {\"name\": \"data-4e6a8369c4777dc759b296d10858d844\"}, \"height\": 400, \"width\": 600, \"$schema\": \"https://vega.github.io/schema/vega-lite/v5.8.0.json\", \"datasets\": {\"data-4e6a8369c4777dc759b296d10858d844\": [{\"\\u8272\": \"a\", \"\\u5909\\u6570\\u540d\": \"\\u5909\\u65701\", \"\\u6700\\u5c0f\\u5024\": 4, \"\\u7b2c1\\u56db\\u5206\\u4f4d\": 6, \"\\u7b2c2\\u56db\\u5206\\u4f4d\": 19, \"\\u7b2c3\\u56db\\u5206\\u4f4d\": 20, \"\\u6700\\u5927\\u5024\": 33, \"\\u5e73\\u5747\\u5024\": 16.6}, {\"\\u8272\": \"b\", \"\\u5909\\u6570\\u540d\": \"\\u5909\\u65702\", \"\\u6700\\u5c0f\\u5024\": 4, \"\\u7b2c1\\u56db\\u5206\\u4f4d\": 7, \"\\u7b2c2\\u56db\\u5206\\u4f4d\": 17, \"\\u7b2c3\\u56db\\u5206\\u4f4d\": 25, \"\\u6700\\u5927\\u5024\": 29, \"\\u5e73\\u5747\\u5024\": 16.8}, {\"\\u8272\": \"a\", \"\\u5909\\u6570\\u540d\": \"\\u5909\\u65703\", \"\\u6700\\u5c0f\\u5024\": 3, \"\\u7b2c1\\u56db\\u5206\\u4f4d\": 10, \"\\u7b2c2\\u56db\\u5206\\u4f4d\": 12, \"\\u7b2c3\\u56db\\u5206\\u4f4d\": 24, \"\\u6700\\u5927\\u5024\": 28, \"\\u5e73\\u5747\\u5024\": 15.8}, {\"\\u8272\": \"b\", \"\\u5909\\u6570\\u540d\": \"\\u5909\\u65704\", \"\\u6700\\u5c0f\\u5024\": 3, \"\\u7b2c1\\u56db\\u5206\\u4f4d\": 6, \"\\u7b2c2\\u56db\\u5206\\u4f4d\": 16, \"\\u7b2c3\\u56db\\u5206\\u4f4d\": 26, \"\\u6700\\u5927\\u5024\": 28, \"\\u5e73\\u5747\\u5024\": 16.2}, {\"\\u8272\": \"a\", \"\\u5909\\u6570\\u540d\": \"\\u5909\\u65705\", \"\\u6700\\u5c0f\\u5024\": 1, \"\\u7b2c1\\u56db\\u5206\\u4f4d\": 6, \"\\u7b2c2\\u56db\\u5206\\u4f4d\": 15, \"\\u7b2c3\\u56db\\u5206\\u4f4d\": 23, \"\\u6700\\u5927\\u5024\": 29, \"\\u5e73\\u5747\\u5024\": 15.4}, {\"\\u8272\": \"b\", \"\\u5909\\u6570\\u540d\": \"\\u5909\\u65706\", \"\\u6700\\u5c0f\\u5024\": 5, \"\\u7b2c1\\u56db\\u5206\\u4f4d\": 10, \"\\u7b2c2\\u56db\\u5206\\u4f4d\": 16, \"\\u7b2c3\\u56db\\u5206\\u4f4d\": 22, \"\\u6700\\u5927\\u5024\": 30, \"\\u5e73\\u5747\\u5024\": 17.4}, {\"\\u8272\": \"a\", \"\\u5909\\u6570\\u540d\": \"\\u5909\\u65707\", \"\\u6700\\u5c0f\\u5024\": 1, \"\\u7b2c1\\u56db\\u5206\\u4f4d\": 9, \"\\u7b2c2\\u56db\\u5206\\u4f4d\": 15, \"\\u7b2c3\\u56db\\u5206\\u4f4d\": 23, \"\\u6700\\u5927\\u5024\": 33, \"\\u5e73\\u5747\\u5024\": 16.0}, {\"\\u8272\": \"b\", \"\\u5909\\u6570\\u540d\": \"\\u5909\\u65708\", \"\\u6700\\u5c0f\\u5024\": 1, \"\\u7b2c1\\u56db\\u5206\\u4f4d\": 10, \"\\u7b2c2\\u56db\\u5206\\u4f4d\": 19, \"\\u7b2c3\\u56db\\u5206\\u4f4d\": 22, \"\\u6700\\u5927\\u5024\": 31, \"\\u5e73\\u5747\\u5024\": 16.6}, {\"\\u8272\": \"a\", \"\\u5909\\u6570\\u540d\": \"\\u5909\\u65709\", \"\\u6700\\u5c0f\\u5024\": 2, \"\\u7b2c1\\u56db\\u5206\\u4f4d\": 7, \"\\u7b2c2\\u56db\\u5206\\u4f4d\": 19, \"\\u7b2c3\\u56db\\u5206\\u4f4d\": 20, \"\\u6700\\u5927\\u5024\": 29, \"\\u5e73\\u5747\\u5024\": 15.4}]}}, {\"mode\": \"vega-lite\"});\n",
"</script>"
],
"text/plain": [
"alt.LayerChart(...)"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"box_plot1 = alt.Chart(df_box).mark_rule(\n",
" color='#A6A6A6', \n",
" opacity=0.8, \n",
" size=3 \n",
").encode(\n",
" y=alt.Y('変数名:N', title='変数名'), \n",
" x=alt.X('最小値:Q', title='値 (黒:平均値 | 白:中央値)'), \n",
" x2=alt.X2('最大値:Q')\n",
").properties(\n",
" width=600, \n",
" height=400,\n",
" title='箱ひげ図' \n",
") \n",
"\n",
"box_plot2 = alt.Chart(df_box).mark_bar(\n",
" color='#00A4A0', \n",
" opacity=0.5, \n",
" size=30 \n",
").encode(\n",
" y=alt.Y('変数名:N', title='変数名'), \n",
" x=alt.X('第1四分位:Q'), \n",
" x2=alt.X2('第3四分位:Q')\n",
")\n",
"\n",
"box_plot3 = alt.Chart(df_box).mark_tick(\n",
" color='#A6A6A6', \n",
" opacity=0.8, \n",
" size=20, \n",
" thickness=3\n",
").encode(\n",
" y=alt.Y('変数名:N', title='変数名'), \n",
" x=alt.X('最小値:Q') \n",
")\n",
"\n",
"box_plot4 = alt.Chart(df_box).mark_tick(\n",
" color='#A6A6A6', \n",
" opacity=0.8, \n",
" size=20, \n",
" thickness=3\n",
").encode(\n",
" y=alt.Y('変数名:N', title='変数名'), \n",
" x=alt.X('最大値:Q')\n",
")\n",
"\n",
"box_plot5 = alt.Chart(df_box).mark_tick(\n",
" color='#000000', \n",
" opacity=0.5, \n",
" size=20, \n",
" thickness=3\n",
").encode(\n",
" y=alt.Y('変数名:N', title='変数名'), \n",
" x=alt.X('平均値:Q')\n",
")\n",
"\n",
"box_plot6 = alt.Chart(df_box).mark_tick(\n",
" color='#FFFFFF', \n",
" opacity=1, \n",
" size=20, \n",
" thickness=3\n",
").encode(\n",
" y=alt.Y('変数名:N', title='変数名'), \n",
" x=alt.X('第2四分位:Q')\n",
")\n",
"\n",
"box_plot1 + box_plot2 + box_plot3 + box_plot4 + box_plot5 + box_plot6 "
]
},
{
"cell_type": "markdown",
"id": "79a5cd22-2c96-4b0d-aad6-877305c657a6",
"metadata": {},
"source": [
"#### 色コードのセット"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "f52b72e0-509d-4f14-a6ba-14a9a93d330b",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"range_ = ['#FF6161', '#EB6E19']"
]
},
{
"cell_type": "markdown",
"id": "e040cd06-06ac-44e0-b6e9-04c7e399f871",
"metadata": {},
"source": [
"#### 色分けする"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "468dd88f-d209-4e5a-834b-7f7b9f2a56d3",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"<style>\n",
" #altair-viz-6d19ff437cf648efa2704de1952afd5b.vega-embed {\n",
" width: 100%;\n",
" display: flex;\n",
" }\n",
"\n",
" #altair-viz-6d19ff437cf648efa2704de1952afd5b.vega-embed details,\n",
" #altair-viz-6d19ff437cf648efa2704de1952afd5b.vega-embed details summary {\n",
" position: relative;\n",
" }\n",
"</style>\n",
"<div id=\"altair-viz-6d19ff437cf648efa2704de1952afd5b\"></div>\n",
"<script type=\"text/javascript\">\n",
" var VEGA_DEBUG = (typeof VEGA_DEBUG == \"undefined\") ? {} : VEGA_DEBUG;\n",
" (function(spec, embedOpt){\n",
" let outputDiv = document.currentScript.previousElementSibling;\n",
" if (outputDiv.id !== \"altair-viz-6d19ff437cf648efa2704de1952afd5b\") {\n",
" outputDiv = document.getElementById(\"altair-viz-6d19ff437cf648efa2704de1952afd5b\");\n",
" }\n",
" const paths = {\n",
" \"vega\": \"https://cdn.jsdelivr.net/npm/vega@5?noext\",\n",
" \"vega-lib\": \"https://cdn.jsdelivr.net/npm/vega-lib?noext\",\n",
" \"vega-lite\": \"https://cdn.jsdelivr.net/npm/vega-lite@5.8.0?noext\",\n",
" \"vega-embed\": \"https://cdn.jsdelivr.net/npm/vega-embed@6?noext\",\n",
" };\n",
"\n",
" function maybeLoadScript(lib, version) {\n",
" var key = `${lib.replace(\"-\", \"\")}_version`;\n",
" return (VEGA_DEBUG[key] == version) ?\n",
" Promise.resolve(paths[lib]) :\n",
" new Promise(function(resolve, reject) {\n",
" var s = document.createElement('script');\n",
" document.getElementsByTagName(\"head\")[0].appendChild(s);\n",
" s.async = true;\n",
" s.onload = () => {\n",
" VEGA_DEBUG[key] = version;\n",
" return resolve(paths[lib]);\n",
" };\n",
" s.onerror = () => reject(`Error loading script: ${paths[lib]}`);\n",
" s.src = paths[lib];\n",
" });\n",
" }\n",
"\n",
" function showError(err) {\n",
" outputDiv.innerHTML = `<div class=\"error\" style=\"color:red;\">${err}</div>`;\n",
" throw err;\n",
" }\n",
"\n",
" function displayChart(vegaEmbed) {\n",
" vegaEmbed(outputDiv, spec, embedOpt)\n",
" .catch(err => showError(`Javascript Error: ${err.message}<br>This usually means there's a typo in your chart specification. See the javascript console for the full traceback.`));\n",
" }\n",
"\n",
" if(typeof define === \"function\" && define.amd) {\n",
" requirejs.config({paths});\n",
" require([\"vega-embed\"], displayChart, err => showError(`Error loading script: ${err.message}`));\n",
" } else {\n",
" maybeLoadScript(\"vega\", \"5\")\n",
" .then(() => maybeLoadScript(\"vega-lite\", \"5.8.0\"))\n",
" .then(() => maybeLoadScript(\"vega-embed\", \"6\"))\n",
" .catch(showError)\n",
" .then(() => displayChart(vegaEmbed));\n",
" }\n",
" })({\"config\": {\"view\": {\"continuousWidth\": 300, \"continuousHeight\": 300}}, \"layer\": [{\"mark\": {\"type\": \"rule\", \"color\": \"#A6A6A6\", \"opacity\": 0.8, \"size\": 3}, \"encoding\": {\"x\": {\"field\": \"\\u6700\\u5c0f\\u5024\", \"title\": \"\\u5024 (\\u9ed2:\\u5e73\\u5747\\u5024 | \\u767d:\\u4e2d\\u592e\\u5024)\", \"type\": \"quantitative\"}, \"x2\": {\"field\": \"\\u6700\\u5927\\u5024\"}, \"y\": {\"field\": \"\\u5909\\u6570\\u540d\", \"title\": \"\\u5909\\u6570\\u540d\", \"type\": \"nominal\"}}, \"title\": \"\\u7bb1\\u3072\\u3052\\u56f3\"}, {\"mark\": {\"type\": \"bar\", \"color\": \"#00A4A0\", \"opacity\": 0.5, \"size\": 30}, \"encoding\": {\"color\": {\"field\": \"\\u8272\", \"legend\": null, \"scale\": {\"range\": [\"#FF6161\", \"#EB6E19\"]}, \"type\": \"nominal\"}, \"x\": {\"field\": \"\\u7b2c1\\u56db\\u5206\\u4f4d\", \"type\": \"quantitative\"}, \"x2\": {\"field\": \"\\u7b2c3\\u56db\\u5206\\u4f4d\"}, \"y\": {\"field\": \"\\u5909\\u6570\\u540d\", \"title\": \"\\u5909\\u6570\\u540d\", \"type\": \"nominal\"}}}, {\"mark\": {\"type\": \"tick\", \"color\": \"#A6A6A6\", \"opacity\": 0.8, \"size\": 20, \"thickness\": 3}, \"encoding\": {\"x\": {\"field\": \"\\u6700\\u5c0f\\u5024\", \"type\": \"quantitative\"}, \"y\": {\"field\": \"\\u5909\\u6570\\u540d\", \"title\": \"\\u5909\\u6570\\u540d\", \"type\": \"nominal\"}}}, {\"mark\": {\"type\": \"tick\", \"color\": \"#A6A6A6\", \"opacity\": 0.8, \"size\": 20, \"thickness\": 3}, \"encoding\": {\"x\": {\"field\": \"\\u6700\\u5927\\u5024\", \"type\": \"quantitative\"}, \"y\": {\"field\": \"\\u5909\\u6570\\u540d\", \"title\": \"\\u5909\\u6570\\u540d\", \"type\": \"nominal\"}}}, {\"mark\": {\"type\": \"tick\", \"color\": \"#000000\", \"opacity\": 0.5, \"size\": 20, \"thickness\": 3}, \"encoding\": {\"x\": {\"field\": \"\\u5e73\\u5747\\u5024\", \"type\": \"quantitative\"}, \"y\": {\"field\": \"\\u5909\\u6570\\u540d\", \"title\": \"\\u5909\\u6570\\u540d\", \"type\": \"nominal\"}}}, {\"mark\": {\"type\": \"tick\", \"color\": \"#FFFFFF\", \"opacity\": 1, \"size\": 20, \"thickness\": 3}, \"encoding\": {\"x\": {\"field\": \"\\u7b2c2\\u56db\\u5206\\u4f4d\", \"type\": \"quantitative\"}, \"y\": {\"field\": \"\\u5909\\u6570\\u540d\", \"title\": \"\\u5909\\u6570\\u540d\", \"type\": \"nominal\"}}}], \"data\": {\"name\": \"data-4e6a8369c4777dc759b296d10858d844\"}, \"height\": 400, \"width\": 600, \"$schema\": \"https://vega.github.io/schema/vega-lite/v5.8.0.json\", \"datasets\": {\"data-4e6a8369c4777dc759b296d10858d844\": [{\"\\u8272\": \"a\", \"\\u5909\\u6570\\u540d\": \"\\u5909\\u65701\", \"\\u6700\\u5c0f\\u5024\": 4, \"\\u7b2c1\\u56db\\u5206\\u4f4d\": 6, \"\\u7b2c2\\u56db\\u5206\\u4f4d\": 19, \"\\u7b2c3\\u56db\\u5206\\u4f4d\": 20, \"\\u6700\\u5927\\u5024\": 33, \"\\u5e73\\u5747\\u5024\": 16.6}, {\"\\u8272\": \"b\", \"\\u5909\\u6570\\u540d\": \"\\u5909\\u65702\", \"\\u6700\\u5c0f\\u5024\": 4, \"\\u7b2c1\\u56db\\u5206\\u4f4d\": 7, \"\\u7b2c2\\u56db\\u5206\\u4f4d\": 17, \"\\u7b2c3\\u56db\\u5206\\u4f4d\": 25, \"\\u6700\\u5927\\u5024\": 29, \"\\u5e73\\u5747\\u5024\": 16.8}, {\"\\u8272\": \"a\", \"\\u5909\\u6570\\u540d\": \"\\u5909\\u65703\", \"\\u6700\\u5c0f\\u5024\": 3, \"\\u7b2c1\\u56db\\u5206\\u4f4d\": 10, \"\\u7b2c2\\u56db\\u5206\\u4f4d\": 12, \"\\u7b2c3\\u56db\\u5206\\u4f4d\": 24, \"\\u6700\\u5927\\u5024\": 28, \"\\u5e73\\u5747\\u5024\": 15.8}, {\"\\u8272\": \"b\", \"\\u5909\\u6570\\u540d\": \"\\u5909\\u65704\", \"\\u6700\\u5c0f\\u5024\": 3, \"\\u7b2c1\\u56db\\u5206\\u4f4d\": 6, \"\\u7b2c2\\u56db\\u5206\\u4f4d\": 16, \"\\u7b2c3\\u56db\\u5206\\u4f4d\": 26, \"\\u6700\\u5927\\u5024\": 28, \"\\u5e73\\u5747\\u5024\": 16.2}, {\"\\u8272\": \"a\", \"\\u5909\\u6570\\u540d\": \"\\u5909\\u65705\", \"\\u6700\\u5c0f\\u5024\": 1, \"\\u7b2c1\\u56db\\u5206\\u4f4d\": 6, \"\\u7b2c2\\u56db\\u5206\\u4f4d\": 15, \"\\u7b2c3\\u56db\\u5206\\u4f4d\": 23, \"\\u6700\\u5927\\u5024\": 29, \"\\u5e73\\u5747\\u5024\": 15.4}, {\"\\u8272\": \"b\", \"\\u5909\\u6570\\u540d\": \"\\u5909\\u65706\", \"\\u6700\\u5c0f\\u5024\": 5, \"\\u7b2c1\\u56db\\u5206\\u4f4d\": 10, \"\\u7b2c2\\u56db\\u5206\\u4f4d\": 16, \"\\u7b2c3\\u56db\\u5206\\u4f4d\": 22, \"\\u6700\\u5927\\u5024\": 30, \"\\u5e73\\u5747\\u5024\": 17.4}, {\"\\u8272\": \"a\", \"\\u5909\\u6570\\u540d\": \"\\u5909\\u65707\", \"\\u6700\\u5c0f\\u5024\": 1, \"\\u7b2c1\\u56db\\u5206\\u4f4d\": 9, \"\\u7b2c2\\u56db\\u5206\\u4f4d\": 15, \"\\u7b2c3\\u56db\\u5206\\u4f4d\": 23, \"\\u6700\\u5927\\u5024\": 33, \"\\u5e73\\u5747\\u5024\": 16.0}, {\"\\u8272\": \"b\", \"\\u5909\\u6570\\u540d\": \"\\u5909\\u65708\", \"\\u6700\\u5c0f\\u5024\": 1, \"\\u7b2c1\\u56db\\u5206\\u4f4d\": 10, \"\\u7b2c2\\u56db\\u5206\\u4f4d\": 19, \"\\u7b2c3\\u56db\\u5206\\u4f4d\": 22, \"\\u6700\\u5927\\u5024\": 31, \"\\u5e73\\u5747\\u5024\": 16.6}, {\"\\u8272\": \"a\", \"\\u5909\\u6570\\u540d\": \"\\u5909\\u65709\", \"\\u6700\\u5c0f\\u5024\": 2, \"\\u7b2c1\\u56db\\u5206\\u4f4d\": 7, \"\\u7b2c2\\u56db\\u5206\\u4f4d\": 19, \"\\u7b2c3\\u56db\\u5206\\u4f4d\": 20, \"\\u6700\\u5927\\u5024\": 29, \"\\u5e73\\u5747\\u5024\": 15.4}]}}, {\"mode\": \"vega-lite\"});\n",
"</script>"
],
"text/plain": [
"alt.LayerChart(...)"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"box_plot1 = alt.Chart(df_box).mark_rule(\n",
" color='#A6A6A6', \n",
" opacity=0.8, \n",
" size=3 \n",
").encode(\n",
" y=alt.Y('変数名:N', title='変数名'), \n",
" x=alt.X('最小値:Q', title='値 (黒:平均値 | 白:中央値)'), \n",
" x2=alt.X2('最大値:Q')\n",
").properties(\n",
" width=600, \n",
" height=400,\n",
" title='箱ひげ図' \n",
") \n",
"\n",
"box_plot2 = alt.Chart(df_box).mark_bar(\n",
" color='#00A4A0', \n",
" opacity=0.5, \n",
" size=30 \n",
").encode(\n",
" y=alt.Y('変数名:N', title='変数名'), \n",
" x=alt.X('第1四分位:Q'), \n",
" x2=alt.X2('第3四分位:Q'), \n",
" color=alt.Color('色:N').scale(range=range_).legend(None),\n",
")\n",
"\n",
"box_plot3 = alt.Chart(df_box).mark_tick(\n",
" color='#A6A6A6', \n",
" opacity=0.8, \n",
" size=20, \n",
" thickness=3\n",
").encode(\n",
" y=alt.Y('変数名:N', title='変数名'), \n",
" x=alt.X('最小値:Q') \n",
")\n",
"\n",
"box_plot4 = alt.Chart(df_box).mark_tick(\n",
" color='#A6A6A6', \n",
" opacity=0.8, \n",
" size=20, \n",
" thickness=3\n",
").encode(\n",
" y=alt.Y('変数名:N', title='変数名'), \n",
" x=alt.X('最大値:Q')\n",
")\n",
"\n",
"box_plot5 = alt.Chart(df_box).mark_tick(\n",
" color='#000000', \n",
" opacity=0.5, \n",
" size=20, \n",
" thickness=3\n",
").encode(\n",
" y=alt.Y('変数名:N', title='変数名'), \n",
" x=alt.X('平均値:Q')\n",
")\n",
"\n",
"box_plot6 = alt.Chart(df_box).mark_tick(\n",
" color='#FFFFFF', \n",
" opacity=1, \n",
" size=20, \n",
" thickness=3\n",
").encode(\n",
" y=alt.Y('変数名:N', title='変数名'), \n",
" x=alt.X('第2四分位:Q')\n",
")\n",
"\n",
"box_plot1 + box_plot2 + box_plot3 + box_plot4 + box_plot5 + box_plot6 "
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.2"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment