Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/python
{
"name": "Python 3",
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
"image": "mcr.microsoft.com/devcontainers/python:1-3.12-bullseye",
"workspaceFolder": "/workspaces/dsp_workshop_dataviz_python",

// Features to add to the dev container. More info: https://containers.dev/features.
// "features": {},

// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],

// Use 'postCreateCommand' to run commands after the container is created.
"postCreateCommand": "pip3 install --user -r requirements.txt",
// "onCreateCommand": "bash .devcontainer/setup.sh",

// Configure tool-specific properties.
"customizations": {
"vscode": {
"extensions": [
"ms-toolsai.jupyter",
"ms-python.python",
"mechatroner.rainbow-csv"
],
// Use Python from conda
"settings": {},
// Use bash
"terminal.integrated.defaultProfile.linux": "bash"
}
}
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
// "remoteUser": "root"
}
11 changes: 11 additions & 0 deletions .github/workflows/build_website.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ on:
push:
branches:
- main
pull_request:
branches:
- main
workflow_dispatch:

# This job installs dependencies, builds the website and pushes it to `gh-pages`
Expand Down Expand Up @@ -33,3 +36,11 @@ jobs:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./_build
# cname: website.com
- if: ${{ github.ref != 'refs/heads/main' }}
name: Save to gh-pages
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./_build
# hide dev version of website in subfolder
destination_dir: dev
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
_build
jupyter_execute
*.docx
219 changes: 219 additions & 0 deletions 1_1_matplotlib.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,219 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "01419663",
"metadata": {},
"source": [
"# Matplotlib\n",
"- A comprehensive library for creating static, animated, and interactive visualizations in Python.\n",
"- Built on NumPy arrays and designed to work with the broader SciPy stack."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "0748b014",
"metadata": {},
"outputs": [],
"source": [
"import matplotlib as mpl\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np"
]
},
{
"cell_type": "markdown",
"id": "348c1b11",
"metadata": {},
"source": [
"## Basic Line Plot\n",
"From Getting Started."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "37ad8b55",
"metadata": {},
"outputs": [],
"source": [
"fig, ax = plt.subplots() # Create a figure containing a single Axes.\n",
"ax.plot([1, 2, 3, 4], [1, 4, 2, 3]) # Plot some data on the Axes.\n",
"plt.show() # Show the figure."
]
},
{
"cell_type": "markdown",
"id": "dd74e2cc",
"metadata": {
"lines_to_next_cell": 0
},
"source": [
"![Anatomy of a matplotlib figure](https://matplotlib.org/stable/_images/anatomy.png)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "2d86fcd1",
"metadata": {},
"outputs": [],
"source": [
"fig, ax = plt.subplots() # Create a figure containing a single Axes.\n",
"ax.plot([1, 2, 3, 4], [1, 4, 2, 3]) # Plot some data on the Axes.\n",
"ax.grid()\n",
"plt.show()"
]
},
{
"cell_type": "markdown",
"id": "0595fdfd",
"metadata": {},
"source": [
"Customize ticks\n",
"- [Ticker API](https://matplotlib.org/stable/api/ticker_api.html)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "0817796f",
"metadata": {},
"outputs": [],
"source": [
"ax.yaxis.set_major_locator(mpl.ticker.MaxNLocator(integer=True))\n",
"# ax.xaxis.set_major_locator(mpl.ticker.MaxNLocator(integer=True))\n",
"ax.get_figure()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "80d2be97",
"metadata": {},
"outputs": [],
"source": [
"mu, sigma = 115, 15\n",
"x = mu + sigma * np.random.randn(10000)\n",
"fig, ax = plt.subplots(figsize=(5, 2.7), layout=\"constrained\")\n",
"# the histogram of the data\n",
"n, bins, patches = ax.hist(x, 50, density=True, facecolor=\"C0\", alpha=0.75)\n",
"\n",
"ax.set_xlabel(\"Length [cm]\")\n",
"ax.set_ylabel(\"Probability\")\n",
"ax.set_title(\"Aardvark lengths\\n (not really)\")\n",
"ax.text(75, 0.025, r\"$\\mu=115,\\ \\sigma=15$\")\n",
"ax.axis([55, 175, 0, 0.03])\n",
"ax.grid(True)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d78dc9ce",
"metadata": {},
"outputs": [],
"source": [
"# ## Proteomics data example"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c290244b",
"metadata": {},
"outputs": [],
"source": [
"import pathlib\n",
"\n",
"import pandas as pd\n",
"\n",
"dir_data = pathlib.Path(\"data\")\n",
"df = pd.read_csv(dir_data / \"proteins\" / \"proteins.csv\", index_col=0)\n",
"df"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "1787a67d",
"metadata": {},
"outputs": [],
"source": [
"x = df.iloc[0]\n",
"x"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "8e27f422",
"metadata": {},
"outputs": [],
"source": [
"ax = x.hist()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "5e525e25",
"metadata": {
"lines_to_next_cell": 2
},
"outputs": [],
"source": [
"fig, ax = plt.subplots()\n",
"n, bins, patches = ax.hist(x, bins=30, alpha=0.7, color=\"C0\")"
]
},
{
"cell_type": "markdown",
"id": "6360d4cd",
"metadata": {},
"source": [
"## Available styles\n",
"Choose your preferred style with it's defaults\n",
"[here](https://matplotlib.org/stable/gallery/style_sheets/style_sheets_reference.html)\n",
"\n",
"```python\n",
"plt.style.use('ggplot')\n",
"```\n",
"\n",
"![ggplot](https://matplotlib.org/stable/_images/sphx_glr_style_sheets_reference_008_2_00x.png)\n",
"![seaborn_v0_8-bright](https://matplotlib.org/stable/_images/sphx_glr_style_sheets_reference_012_2_00x.png)\n",
"![seaborn_v0_8-white](https://matplotlib.org/stable/_images/sphx_glr_style_sheets_reference_025_2_00x.png)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "f32690b4",
"metadata": {},
"outputs": [],
"source": [
"with plt.style.context(\"ggplot\"):\n",
" fig, ax = plt.subplots()\n",
" n, bins, patches = ax.hist(x, bins=30, alpha=0.7)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "41efb93a",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"jupytext": {
"cell_metadata_filter": "-all",
"main_language": "python",
"notebook_metadata_filter": "-all"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
93 changes: 93 additions & 0 deletions 1_1_matplotlib.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# %% [markdown]
# # Matplotlib
# - A comprehensive library for creating static, animated, and interactive visualizations in Python.
# - Built on NumPy arrays and designed to work with the broader SciPy stack.

# %%
import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np

# %% [markdown]
# ## Basic Line Plot
# From Getting Started.

# %%
fig, ax = plt.subplots() # Create a figure containing a single Axes.
ax.plot([1, 2, 3, 4], [1, 4, 2, 3]) # Plot some data on the Axes.
plt.show() # Show the figure.

# %% [markdown]
# ![Anatomy of a matplotlib figure](https://matplotlib.org/stable/_images/anatomy.png)
# %%
fig, ax = plt.subplots() # Create a figure containing a single Axes.
ax.plot([1, 2, 3, 4], [1, 4, 2, 3]) # Plot some data on the Axes.
ax.grid()
plt.show()

# %% [markdown]
# Customize ticks
# - [Ticker API](https://matplotlib.org/stable/api/ticker_api.html)

# %%
ax.yaxis.set_major_locator(mpl.ticker.MaxNLocator(integer=True))
# ax.xaxis.set_major_locator(mpl.ticker.MaxNLocator(integer=True))
ax.get_figure()

# %%
mu, sigma = 115, 15
x = mu + sigma * np.random.randn(10000)
fig, ax = plt.subplots(figsize=(5, 2.7), layout="constrained")
# the histogram of the data
n, bins, patches = ax.hist(x, 50, density=True, facecolor="C0", alpha=0.75)

ax.set_xlabel("Length [cm]")
ax.set_ylabel("Probability")
ax.set_title("Aardvark lengths\n (not really)")
ax.text(75, 0.025, r"$\mu=115,\ \sigma=15$")
ax.axis([55, 175, 0, 0.03])
ax.grid(True)

# %%
# ## Proteomics data example

# %%
import pathlib

import pandas as pd

dir_data = pathlib.Path("data")
df = pd.read_csv(dir_data / "proteins" / "proteins.csv", index_col=0)
df

# %%
x = df.iloc[0]
x

# %%
ax = x.hist()

# %%
fig, ax = plt.subplots()
n, bins, patches = ax.hist(x, bins=30, alpha=0.7, color="C0")


# %% [markdown]
# ## Available styles
# Choose your preferred style with it's defaults
# [here](https://matplotlib.org/stable/gallery/style_sheets/style_sheets_reference.html)
#
# ```python
# plt.style.use('ggplot')
# ```
#
# ![ggplot](https://matplotlib.org/stable/_images/sphx_glr_style_sheets_reference_008_2_00x.png)
# ![seaborn_v0_8-bright](https://matplotlib.org/stable/_images/sphx_glr_style_sheets_reference_012_2_00x.png)
# ![seaborn_v0_8-white](https://matplotlib.org/stable/_images/sphx_glr_style_sheets_reference_025_2_00x.png)

# %%
with plt.style.context("ggplot"):
fig, ax = plt.subplots()
n, bins, patches = ax.hist(x, bins=30, alpha=0.7)

# %%
Loading
Loading