0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Google Colabを学びたい Step3 箱ひげ図を書く

Posted at

はじめに

GoogleColabを学びたいStep3です。今回は箱ひげ図を書いていこうと思います!!

成果物

地域別の家賃の比較をした箱ひげ図です。
image.png

ソースコード

# 必要なライブラリをインポート
import numpy as np
import matplotlib.pyplot as plt

# 地域ごとの家賃データ(月額)※単位:円
tokyo_rent = [85000, 78000, 92000, 99000, 87000, 105000, 89000, 97000, 91000, 94000]
osaka_rent = [65000, 59000, 70000, 72000, 68000, 64000, 75000, 73000, 67000, 71000]
nagoya_rent = [55000, 50000, 52000, 60000, 58000, 57000, 54000, 61000, 62000, 59000]

# 家賃データをリストにまとめる(箱ひげ図で比較するため)
data = [tokyo_rent, osaka_rent, nagoya_rent]

# 箱ひげ図を描画
plt.figure(figsize=(10, 5))  # グラフサイズ指定
plt.boxplot(data, labels=["Tokyo", "Osaka", "Nagoya"], vert=True)

# グラフタイトルと軸ラベル(英語で表示)
plt.title("Monthly Rent Comparison by City")
plt.ylabel("Rent (Yen)")

# グリッド表示
plt.grid(True)

# グラフを表示
plt.show()

こんな簡単に書けるといいですね!!

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?