Skip to content

Instantly share code, notes, and snippets.

@yuji96
Last active September 30, 2023 15:35
Show Gist options
  • Save yuji96/306b7e87179722b5e90d096c0307e727 to your computer and use it in GitHub Desktop.
Save yuji96/306b7e87179722b5e90d096c0307e727 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/gist/yuji96/306b7e87179722b5e90d096c0307e727/fuji_blank.ipynb)"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"# データの準備\n",
"\n",
"from math import cos, pi\n",
"import random\n",
"import numpy as np\n",
"\n",
"\n",
"## 富士山の外形\n",
"def f(x):\n",
" if abs(x) <= 1:\n",
" return x**4 - x**2 + 6 - 1\n",
" else:\n",
" return 12 / (abs(x) + 1) - 1\n",
"\n",
"\n",
"def g(x):\n",
" return 1 / 2 * cos(2 * pi * x) + 7 / 2 - 1\n",
"\n",
"\n",
"x1 = np.linspace(-5, 5, 100)\n",
"fx = [f(x) for x in x1]\n",
"\n",
"x2 = np.linspace(-2, 2, 50)\n",
"gx = [g(x) for x in x2]\n",
"\n",
"## 星の座標\n",
"star_x = [random.uniform(-5, 5) for _ in range(15)]\n",
"star_y = [random.uniform(f(x), 8) for x in star_x]\n",
"\n",
"## ビルの位置と高さ\n",
"bldg_x = [random.uniform(-5, 5) for _ in range(10)]\n",
"bldg_y = [random.uniform(0.5, 3) for _ in range(10)]"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"import matplotlib.pyplot as plt"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"そのまま `plt.hoge()` を実行しただけだと物足りない。例えば、次のようなことができないだろうか。\n",
"\n",
"- 散布図の点を星にする\n",
"- 星のサイズを変える\n",
"- ビルの色を変える\n",
"- ビルに枠線をつける"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"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.9.13"
},
"orig_nbformat": 4
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment