Last active
November 30, 2021 21:32
-
-
Save kinonotofu/200a2ba83af174197feb1a3557b999ab to your computer and use it in GitHub Desktop.
psychrochart.ipynb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"nbformat": 4, | |
"nbformat_minor": 0, | |
"metadata": { | |
"colab": { | |
"name": "psychrochart.ipynb", | |
"provenance": [], | |
"collapsed_sections": [], | |
"include_colab_link": true | |
}, | |
"kernelspec": { | |
"name": "python3", | |
"display_name": "Python 3" | |
}, | |
"language_info": { | |
"name": "python" | |
} | |
}, | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "view-in-github", | |
"colab_type": "text" | |
}, | |
"source": [ | |
"<a href=\"https://colab.research.google.com/gist/kinonotofu/200a2ba83af174197feb1a3557b999ab/psychrochart.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "qkqh8go8L74s" | |
}, | |
"source": [ | |
"# 1.はじめに\n", | |
"このノートブックはpsychrochartの使い方を説明するものです。詳しくは[こちらの記事](https://zenn.dev/kinonotofu/articles/210f2835d9a6e3)を読んでください。\n" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "1nzAL-M3lcE_" | |
}, | |
"source": [ | |
"# 2. psychrochartのインストール" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "Vguc3CmzlYJz" | |
}, | |
"source": [ | |
"!pip install psychrochart" | |
], | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "VRIvEB4emLf2" | |
}, | |
"source": [ | |
"# サンプルの実行\n", | |
"from psychrochart import PsychroChart\n", | |
"\n", | |
"chart_default = PsychroChart('default')\n", | |
"ax = chart_default.plot()\n", | |
"ax.get_figure()" | |
], | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "3imvwQxKodBU" | |
}, | |
"source": [ | |
"# 3. ベースとなる空気線図のスタイルの設定" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "JUvUsNPbm5v2" | |
}, | |
"source": [ | |
"# スタイルのデフォルト設定の読み込み\n", | |
"from psychrochart import load_config\n", | |
"config_style = load_config('default')\n", | |
"config_style" | |
], | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "RbcLEBbgS4UZ" | |
}, | |
"source": [ | |
"## 線と塗りつぶし領域の表示の有無の設定" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "HJSvCJpBtECB" | |
}, | |
"source": [ | |
"# 線と塗りつぶし領域の表示の有無の設定\n", | |
"config_style['chart_params']['with_constant_dry_temp'] = False # 乾球温度\n", | |
"config_style['chart_params']['with_constant_h'] = False # 比エンタルピー\n", | |
"config_style['chart_params']['with_constant_humidity'] = False # 絶対湿度\n", | |
"config_style['chart_params']['with_constant_rh'] = False # 相対湿度\n", | |
"config_style['chart_params']['with_constant_v'] = True # 比容積\n", | |
"config_style['chart_params']['with_constant_wet_temp'] = True # 湿球温度\n", | |
"config_style['chart_params']['with_zones'] = False # 塗りつぶし領域\n", | |
"\n", | |
"# 描画して設定を確認\n", | |
"chart = PsychroChart(config_style)\n", | |
"ax = chart.plot()\n", | |
"ax.get_figure()" | |
], | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "C2Vs5B-WS8ce" | |
}, | |
"source": [ | |
"## 線の色と線種と線の太さの設定\n", | |
"* 色は[R, G, B]でそれぞれ0.0-1.0の範囲の値を設定します。4つ目の要素として0.0-1.0の範囲の透過度を設定する事もできこの場合は0に近い値が透明度が高くなります。\n", | |
"* 線種は連続線'-'、破線'--'、点線':'、一点鎖線'-.'の種類があります。\n", | |
"* 線の太さは値が大きいほど太くなります。" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "5JiSeG3JtRdI" | |
}, | |
"source": [ | |
"# 設定を元に戻す\n", | |
"config_style['chart_params']['with_constant_dry_temp'] = True # 乾球温度\n", | |
"config_style['chart_params']['with_constant_h'] = True # 比エンタルピー\n", | |
"config_style['chart_params']['with_constant_humidity'] = True # 絶対湿度\n", | |
"config_style['chart_params']['with_constant_rh'] = True # 相対湿度\n", | |
"config_style['chart_params']['with_zones'] = True # 塗りつぶし領域" | |
], | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "oycP7MPl10RA" | |
}, | |
"source": [ | |
"# 乾球温度\n", | |
"config_style['constant_dry_temp']['color'] = [1.0, 0.0, 0.0] # 線の色\n", | |
"config_style['constant_dry_temp']['linestyle'] = '-' # 線種\n", | |
"config_style['constant_dry_temp']['linewidth'] = 2 # 線の太さ\n", | |
"\n", | |
"# 比エンタルピー\n", | |
"config_style['constant_h']['color'] = [0.0, 0.0, 0.0] # 線の色\n", | |
"config_style['constant_h']['linestyle'] = '--' # 線種\n", | |
"config_style['constant_h']['linewidth'] = 0.5 # 線の太さ\n", | |
"\n", | |
"# 絶対湿度\n", | |
"config_style['constant_humidity']['color'] = [0.0, 0.0, 1.0] # 線の色\n", | |
"config_style['constant_humidity']['linestyle'] = '-' # 線種\n", | |
"config_style['constant_humidity']['linewidth'] = 2 # 線の太さ\n", | |
"\n", | |
"# 相対湿度\n", | |
"config_style['constant_rh']['color'] = [0.0, 0.0, 0.0] # 線の色\n", | |
"config_style['constant_rh']['linestyle'] = '-.' # 線種\n", | |
"config_style['constant_rh']['linewidth'] = 0.5 # 線の太さ\n", | |
"\n", | |
"# 比容積\n", | |
"config_style['constant_v']['color'] = [0.0, 0.0, 0.0] # 線の色\n", | |
"config_style['constant_v']['linestyle'] = '--' # 線種\n", | |
"config_style['constant_v']['linewidth'] = 0.5 # 線の太さ\n", | |
"\n", | |
"# 湿球温度\n", | |
"config_style['constant_wet_temp']['color'] = [0.0, 0.0, 0.0] # 線の色\n", | |
"config_style['constant_wet_temp']['linestyle'] = '-.' # 線種\n", | |
"config_style['constant_wet_temp']['linewidth'] = 0.5 # 線の太さ\n", | |
"\n", | |
"# 飽和曲線\n", | |
"config_style['saturation']['color'] = [0.0, 0.0, 0.0] # 線の色\n", | |
"config_style['saturation']['linestyle'] = '-' # 線種\n", | |
"config_style['saturation']['linewidth'] = 0.5 # 線の太さ\n", | |
"\n", | |
"# 描画して設定を確認\n", | |
"chart = PsychroChart(config_style)\n", | |
"ax = chart.plot()\n", | |
"ax.get_figure()" | |
], | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "PCmkAkhETcq8" | |
}, | |
"source": [ | |
"## 描画する線と数値の間隔の設定\n", | |
"\n", | |
"\n", | |
"\n" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "7txHwQinnzbW" | |
}, | |
"source": [ | |
"# 色を付けて太くした線を黒い細線にする。\n", | |
"config_style['constant_dry_temp']['color'] = [0.0, 0.0, 0.0] # 線の色\n", | |
"config_style['constant_dry_temp']['linewidth'] = 0.5 # 線の太さ\n", | |
"config_style['constant_humidity']['color'] = [0.0, 0.0, 0.0] # 線の色\n", | |
"config_style['constant_humidity']['linewidth'] = 0.5 # 線の太さ" | |
], | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "2sp9PB7auTqW" | |
}, | |
"source": [ | |
"# 全体\n", | |
"config_style['limits']['range_temp_c'] = [0, 50] # グラフの左右の端を乾球温度の範囲で指定\n", | |
"config_style['limits']['range_humidity_g_kg'] = [0, 40] # グラフの上下の端を絶対湿度の範囲で指定\n", | |
"\n", | |
"# 乾球温度\n", | |
"config_style['chart_params']['constant_temp_step'] = 1 # 線の間隔\n", | |
"config_style['chart_params']['constant_temp_label_step'] = 5 # 数値の間隔\n", | |
"\n", | |
"# 比エンタルピー\n", | |
"config_style['chart_params']['range_h'] = [5, 155] # 線の両端の値\n", | |
"config_style['chart_params']['constant_h_step'] = 5 # 線の間隔\n", | |
"config_style['chart_params']['constant_h_labels'] = [5, 25, 50, 75, 100, 125] # 表示する数値\n", | |
"config_style['chart_params']['constant_h_labels_loc'] = 1.0 # 数値の位置(0で左寄せ、1で右寄せ)\n", | |
"\n", | |
"# 絶対湿度\n", | |
"config_style['chart_params']['constant_humid_step'] = 1 # 線の間隔\n", | |
"config_style['chart_params']['constant_humid_label_step'] = 2 # 数値の間隔\n", | |
"config_style['chart_params']['constant_humid_label_include_limits'] = True # 上下端の数値を表示するか\n", | |
"\n", | |
"# 相対湿度\n", | |
"config_style['chart_params']['constant_rh_curves'] = [10, 20, 30, 40, 45, 50, 55, 60, 70, 80, 90] # 線の値\n", | |
"config_style['chart_params']['constant_rh_labels'] = [20, 30, 40, 50, 60, 70, 80] # 表示する数値\n", | |
"config_style['chart_params']['constant_rh_labels_loc'] = 0.85 # 数値の位置(0で左寄せ、1で右寄せ)\n", | |
"\n", | |
"# 比容積\n", | |
"config_style['chart_params']['range_vol_m3_kg'] = [0.78, 0.98] # 線の両端の値\n", | |
"config_style['chart_params']['constant_v_step'] = 0.02 # 線の間隔\n", | |
"config_style['chart_params']['constant_v_labels'] = [0.8, 0.9, 0.96] # 表示する数値\n", | |
"config_style['chart_params']['constant_v_labels_loc'] = 1.0 # 数値の位置(0で左寄せ、1で右寄せ)\n", | |
"\n", | |
"# 湿球温度\n", | |
"config_style['chart_params']['range_wet_temp'] = [-10, 40] # 線の両端の値\n", | |
"config_style['chart_params']['constant_wet_temp_step'] = 5 # 線の間隔\n", | |
"config_style['chart_params']['constant_wet_temp_labels'] = [0, 5, 10, 15, 20, 25, 30, 35] # 表示する数値\n", | |
"config_style['chart_params']['constant_wet_temp_labels_loc'] = 0.05 # 数値の位置(0で左寄せ、1で右寄せ)\n", | |
"\n", | |
"# 描画して設定を確認\n", | |
"chart = PsychroChart(config_style)\n", | |
"ax = chart.plot()\n", | |
"ax.get_figure()" | |
], | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "XouBc2YpT79S" | |
}, | |
"source": [ | |
"## 図の大きさ、タイトルや軸の設定" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "bLn-osi7vwQG" | |
}, | |
"source": [ | |
"!pip install japanize-matplotlib" | |
], | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "nIr172H5vyg3" | |
}, | |
"source": [ | |
"# 日本語フォントの設定\n", | |
"import japanize_matplotlib" | |
], | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "NUYQ8eeTqSEz" | |
}, | |
"source": [ | |
"# 全体の設定\n", | |
"config_style['figure']['title'] = '空気線図' # タイトルの設定\n", | |
"config_style['figure']['figsize'] = [16, 9] # 図の大きさ\n", | |
"config_style['figure']['partial_axis'] = True # Falseだと左と上に線が追加されて図が囲まれる\n", | |
"config_style['figure']['position'] = [0.0025, 0.075, 0.925, 0.875] # 図の中のグラフの位置[左, 下, 幅, 高さ] \n", | |
"\n", | |
"# X軸の設定\n", | |
"config_style['figure']['x_axis'] = {'color': [0.2, 0.2, 0.2], \n", | |
" 'linestyle': '-', \n", | |
" 'linewidth': 2} # 軸の色、線種、太さ\n", | |
"config_style['figure']['x_axis_labels'] = {'color': [0.2, 0.2, 0.2], \n", | |
" 'fontsize': 10} # ラベルの色、フォントサイズ\n", | |
"config_style['figure']['x_axis_ticks'] = {'color': [0.2, 0.2, 0.2],\n", | |
" 'direction': 'out'} # 目盛の色、方向\n", | |
"config_style['figure']['x_label'] = '乾球温度, $°C$' # ラベルの文字\n", | |
"\n", | |
"# Y軸の設定\n", | |
"config_style['figure']['y_axis'] = {'color': [0.2, 0.2, 0.2], \n", | |
" 'linestyle': '-', \n", | |
" 'linewidth': 2} # 軸の色、線種、太さ\n", | |
"config_style['figure']['y_axis_labels'] = {'color': [0.2, 0.2, 0.2], \n", | |
" 'fontsize': 10} # ラベルの色、フォントサイズ\n", | |
"config_style['figure']['y_axis_ticks'] = {'color': [0.2, 0.2, 0.2], \n", | |
" 'direction': 'out'} # 目盛の色、方向\n", | |
"config_style['figure']['y_label'] = '絶対湿度, $g_w / kg_{da}$' # ラベルの文字\n", | |
"\n", | |
"# 描画して設定を確認 \n", | |
"chart = PsychroChart(config_style)\n", | |
"ax = chart.plot()\n", | |
"ax.get_figure()" | |
], | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "1I9G4m9kUJfs" | |
}, | |
"source": [ | |
"## その他の設定" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "VSXfSD5rD8YK" | |
}, | |
"source": [ | |
"# 大気圧の設定(Noneなら標準大気圧)\n", | |
"config_style['limits']['pressure_kpa'] = None\n", | |
"# 指定高度での標準大気圧にする(pressure_kpaが設定されてされていればそちらを優先)\n", | |
"config_style['limits']['altitude_m'] = 0\n", | |
"\n", | |
"# 直線近似する曲線の乾球温度での間隔(小さいほうが滑らか)\n", | |
"config_style['limits']['step_temp'] = 1.0" | |
], | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "nFKGWb_HUUEz" | |
}, | |
"source": [ | |
"# 4. 追加表示データの設定" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "p78kDNbXogGr" | |
}, | |
"source": [ | |
"## 領域の塗りつぶし" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "NOncjsztocJB" | |
}, | |
"source": [ | |
"# 領域の塗りつぶしのデフォルト設定の読み込み\n", | |
"from psychrochart import load_zones\n", | |
"config_zone = load_zones()\n", | |
"config_zone" | |
], | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "uzoA4u4C0Xlh" | |
}, | |
"source": [ | |
"config_zone['zones'].pop() # listの末尾のデータを削除\n", | |
"chart = PsychroChart(config_style, config_zone)\n", | |
"ax = chart.plot()\n", | |
"ax.get_figure()" | |
], | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "5TaX9gCf0PZ-" | |
}, | |
"source": [ | |
"# 末尾にデータを追加\n", | |
"config_zone['zones'].append(config_zone['zones'][0].copy())\n", | |
"\n", | |
"# 追加したデータの設定\n", | |
"config_zone['zones'][1]['label'] = 'Cold' # 領域の名称\n", | |
"config_zone['zones'][1]['points_x'] = [0, 15] # x座標(ここでは乾球温度)\n", | |
"config_zone['zones'][1]['points_y'] = [0, 100] # y座標(ここでは相対湿度)\n", | |
"config_zone['zones'][1]['style'] = {'edgecolor': [0.0, 0.0, 0.8, 0.8],\n", | |
" 'facecolor': [0.0, 0.0, 0.8, 0.5],\n", | |
" 'linestyle': '--',\n", | |
" 'linewidth': 2} # 塗りつぶしの描画設定(辺の色、面の色、線種、線の太さ)\n", | |
"config_zone['zones'][1]['zone_type'] = 'dbt-rh' # 座標位置の指定タイプ、他に'xy-points'が指定できる\n", | |
"\n", | |
"# 描画して設定を確認\n", | |
"chart = PsychroChart(config_style, config_zone)\n", | |
"ax = chart.plot()\n", | |
"ax.get_figure()" | |
], | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "Y3RbzDwu8mlc" | |
}, | |
"source": [ | |
"## 点と線のプロット" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "SgIazAgJRefG" | |
}, | |
"source": [ | |
"# 点を一つだけプロット(系列の名前,色とマーカーの種類とサイズ、乾球温度と相対湿度を指定)\n", | |
"point = {'point1': {'label': 'point1',\n", | |
" 'style': {'color': [0.85, 0.0, 0.0, 0.5],\n", | |
" 'marker': 'o', \n", | |
" 'markersize': 10},\n", | |
" 'xy': (26, 60)}}\n", | |
"\n", | |
"# 描画して設定を確認\n", | |
"chart = PsychroChart(config_style, config_zone)\n", | |
"ax = chart.plot()\n", | |
"chart.plot_points_dbt_rh(point)\n", | |
"ax.get_figure()" | |
], | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "RUgRGE3a8jPN" | |
}, | |
"source": [ | |
"# 二つの点をそれらをつなぐ線をプロット(系列の名前,色とマーカーの種類とサイズ、乾球温度と相対湿度を指定)\n", | |
"points = {'pointa': {'label': 'pointA',\n", | |
" 'style': {'color': [0.855, 0.004, 0.278, 0.8],\n", | |
" 'marker': 'X', \n", | |
" 'markersize': 15},\n", | |
" 'xy': (31.06, 32.9)},\n", | |
" 'pointb': {'label': 'pointB',\n", | |
" 'style': {'color': [0.573, 0.106, 0.318, 0.5],\n", | |
" 'marker': 'x', \n", | |
" 'markersize': 10},\n", | |
" 'xy': (36.7, 25.0)}}\n", | |
"# 点をつなぐ線(始点と終点、線の名前、線の色と太さと種類を指定)\n", | |
"connectors = [{'start': 'pointa',\n", | |
" 'end': 'pointb',\n", | |
" 'label': 'line1',\n", | |
" 'style': {'color': [0.573, 0.106, 0.318, 0.7],\n", | |
" \"linewidth\": 2, \n", | |
" \"linestyle\": \"-.\"}}]\n", | |
"\n", | |
"# 描画して設定を確認\n", | |
"chart = PsychroChart(config_style, config_zone)\n", | |
"ax = chart.plot()\n", | |
"chart.plot_points_dbt_rh(points, connectors)\n", | |
"ax.get_figure()" | |
], | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "PiOLI_cC8yrS" | |
}, | |
"source": [ | |
"# 複数の点を一度にプロット\n", | |
"import numpy as np\n", | |
"\n", | |
"n = 1000 # データの個数\n", | |
"temp_array = np.random.rand(n)*40-5 # 乾球温度をランダムにn個作成\n", | |
"humid_array = np.random.rand(n)*100 # 相対湿度をランダムにn個作成\n", | |
"\n", | |
"points_array = {'points_series_name': (temp_array, humid_array)}\n", | |
"points_style = {'s': 9, 'alpha': 0.8, 'color': 'darkorange'}\n", | |
"\n", | |
"chart = PsychroChart(config_style, config_zone)\n", | |
"ax = chart.plot()\n", | |
"chart.plot_points_dbt_rh(points_array, scatter_style=points_style)\n", | |
"ax.get_figure()" | |
], | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "Vfs7PZN98ksa" | |
}, | |
"source": [ | |
"# 矢印(細い三角形)のプロット(矢印の名前、色、乾球温度と相対湿度)\n", | |
"points_pair = {'wedgea': {'label': 'wedgeA',\n", | |
" 'style': {'color': [0.0, 1.0, 0.0]},\n", | |
" 'xy': [(25.0, 60), (18, 95)]}}\n", | |
"chart = PsychroChart(config_style, config_zone)\n", | |
"ax = chart.plot()\n", | |
"chart.plot_arrows_dbt_rh(points_pair)\n", | |
"ax.get_figure()" | |
], | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "QliRq5_78nye" | |
}, | |
"source": [ | |
"## 凡例の追加" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "7sLGgPKYXkHi" | |
}, | |
"source": [ | |
"# 凡例の追加\n", | |
"chart = PsychroChart(config_style, config_zone)\n", | |
"ax = chart.plot()\n", | |
"chart.plot_points_dbt_rh(points, connectors)\n", | |
"\n", | |
"# 凡例の設定(マーカーのサイズ、枠の有無m」フォントサイズ、凡例の間隔)\n", | |
"chart.plot_legend(markerscale=.7, frameon=False, fontsize=16, labelspacing=0.5)\n", | |
"ax.get_figure()" | |
], | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "bg8mphvL8dSL" | |
}, | |
"source": [ | |
"#ベースの空気線図の凡例の設定\n", | |
"# 凡例のラベル名、空文字にしておくと凡例が表示されない\n", | |
"config_style['chart_params']['constant_temp_label'] = ''\n", | |
"config_style['chart_params']['constant_h_label'] = '' \n", | |
"config_style['chart_params']['constant_humid_label'] = '' \n", | |
"config_style['chart_params']['constant_rh_label'] = '' \n", | |
"config_style['chart_params']['constant_v_label'] = '' \n", | |
"config_style['chart_params']['constant_wet_temp_label'] = '' \n", | |
"\n", | |
"# 凡例を表示したいときにマーカーを透明にする\n", | |
"config_style['constant_dry_temp']['markerfacecolor'] = [0, 0, 0, 0] \n", | |
"config_style['constant_h']['markerfacecolor'] = [0, 0, 0, 0]\n", | |
"config_style['constant_humidity']['markerfacecolor'] = [0, 0, 0, 0]\n", | |
"config_style['constant_rh']['markerfacecolor'] = [0, 0, 0, 0] \n", | |
"config_style['constant_v']['markerfacecolor'] = [0, 0, 0, 0] \n", | |
"config_style['constant_wet_temp']['markerfacecolor'] = [0, 0, 0, 0]\n", | |
"\n", | |
"# 描画して設定を確認\n", | |
"chart = PsychroChart(config_style)\n", | |
"ax = chart.plot()\n", | |
"chart.plot_points_dbt_rh(points, connectors)\n", | |
"chart.plot_legend(markerscale=.7, frameon=False, fontsize=16, labelspacing=0.5)\n", | |
"ax.get_figure()" | |
], | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "cKjJp-bjMC8-" | |
}, | |
"source": [ | |
"# 5. 画像ファイルの書き出し" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "jwjP5TQGMJ3_" | |
}, | |
"source": [ | |
"png_filepath = './img.png'\n", | |
"chart.save(png_filepath) # pngの場合はフォーマットを指定しなくてもよい" | |
], | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "5_iCL4zbMWCP" | |
}, | |
"source": [ | |
"svg_filepath = './img.svg'\n", | |
"chart.save(svg_filepath, format='svg')" | |
], | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/", | |
"height": 17 | |
}, | |
"id": "37QFgYuKMiHC", | |
"outputId": "645b3f13-d687-4ca5-ec9b-017012df4c53" | |
}, | |
"source": [ | |
"# ファイルのダウンロード\n", | |
"from google.colab import files\n", | |
"files.download(png_filepath)\n", | |
"files.download(svg_filepath)" | |
], | |
"execution_count": null, | |
"outputs": [ | |
{ | |
"output_type": "display_data", | |
"data": { | |
"application/javascript": [ | |
"\n", | |
" async function download(id, filename, size) {\n", | |
" if (!google.colab.kernel.accessAllowed) {\n", | |
" return;\n", | |
" }\n", | |
" const div = document.createElement('div');\n", | |
" const label = document.createElement('label');\n", | |
" label.textContent = `Downloading \"${filename}\": `;\n", | |
" div.appendChild(label);\n", | |
" const progress = document.createElement('progress');\n", | |
" progress.max = size;\n", | |
" div.appendChild(progress);\n", | |
" document.body.appendChild(div);\n", | |
"\n", | |
" const buffers = [];\n", | |
" let downloaded = 0;\n", | |
"\n", | |
" const channel = await google.colab.kernel.comms.open(id);\n", | |
" // Send a message to notify the kernel that we're ready.\n", | |
" channel.send({})\n", | |
"\n", | |
" for await (const message of channel.messages) {\n", | |
" // Send a message to notify the kernel that we're ready.\n", | |
" channel.send({})\n", | |
" if (message.buffers) {\n", | |
" for (const buffer of message.buffers) {\n", | |
" buffers.push(buffer);\n", | |
" downloaded += buffer.byteLength;\n", | |
" progress.value = downloaded;\n", | |
" }\n", | |
" }\n", | |
" }\n", | |
" const blob = new Blob(buffers, {type: 'application/binary'});\n", | |
" const a = document.createElement('a');\n", | |
" a.href = window.URL.createObjectURL(blob);\n", | |
" a.download = filename;\n", | |
" div.appendChild(a);\n", | |
" a.click();\n", | |
" div.remove();\n", | |
" }\n", | |
" " | |
], | |
"text/plain": [ | |
"<IPython.core.display.Javascript object>" | |
] | |
}, | |
"metadata": {} | |
}, | |
{ | |
"output_type": "display_data", | |
"data": { | |
"application/javascript": [ | |
"download(\"download_c2287aad-61f3-4783-871e-54ee69f02bc8\", \"img.png\", 756480)" | |
], | |
"text/plain": [ | |
"<IPython.core.display.Javascript object>" | |
] | |
}, | |
"metadata": {} | |
}, | |
{ | |
"output_type": "display_data", | |
"data": { | |
"application/javascript": [ | |
"\n", | |
" async function download(id, filename, size) {\n", | |
" if (!google.colab.kernel.accessAllowed) {\n", | |
" return;\n", | |
" }\n", | |
" const div = document.createElement('div');\n", | |
" const label = document.createElement('label');\n", | |
" label.textContent = `Downloading \"${filename}\": `;\n", | |
" div.appendChild(label);\n", | |
" const progress = document.createElement('progress');\n", | |
" progress.max = size;\n", | |
" div.appendChild(progress);\n", | |
" document.body.appendChild(div);\n", | |
"\n", | |
" const buffers = [];\n", | |
" let downloaded = 0;\n", | |
"\n", | |
" const channel = await google.colab.kernel.comms.open(id);\n", | |
" // Send a message to notify the kernel that we're ready.\n", | |
" channel.send({})\n", | |
"\n", | |
" for await (const message of channel.messages) {\n", | |
" // Send a message to notify the kernel that we're ready.\n", | |
" channel.send({})\n", | |
" if (message.buffers) {\n", | |
" for (const buffer of message.buffers) {\n", | |
" buffers.push(buffer);\n", | |
" downloaded += buffer.byteLength;\n", | |
" progress.value = downloaded;\n", | |
" }\n", | |
" }\n", | |
" }\n", | |
" const blob = new Blob(buffers, {type: 'application/binary'});\n", | |
" const a = document.createElement('a');\n", | |
" a.href = window.URL.createObjectURL(blob);\n", | |
" a.download = filename;\n", | |
" div.appendChild(a);\n", | |
" a.click();\n", | |
" div.remove();\n", | |
" }\n", | |
" " | |
], | |
"text/plain": [ | |
"<IPython.core.display.Javascript object>" | |
] | |
}, | |
"metadata": {} | |
}, | |
{ | |
"output_type": "display_data", | |
"data": { | |
"application/javascript": [ | |
"download(\"download_ec8138c5-725c-4940-961f-117b54a9ddf8\", \"img.svg\", 128834)" | |
], | |
"text/plain": [ | |
"<IPython.core.display.Javascript object>" | |
] | |
}, | |
"metadata": {} | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "Jh1ZHRZfV-Rv" | |
}, | |
"source": [ | |
"" | |
], | |
"execution_count": null, | |
"outputs": [] | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment