Skip to content

Instantly share code, notes, and snippets.

@kolibril13
Created December 15, 2024 18:55
Show Gist options
  • Save kolibril13/2962adb86f1c9a1da3282bca31cc6112 to your computer and use it in GitHub Desktop.
Save kolibril13/2962adb86f1c9a1da3282bca31cc6112 to your computer and use it in GitHub Desktop.
matplotlib inline with fixed version
# /// script
# requires-python = ">=3.12"
# dependencies = [
# "matplotlib==3.10.0",
# ]
# ///
# header was generated with this one terminal command:
# uv init --script foo.py
# echo -e 'matplotlib' | \
# uv pip compile --no-deps - | \
# grep '==' | \
# xargs -L 1 uv add --script foo.py
import matplotlib.pyplot as plt
import numpy as np
import os
# Retrieve the color from the environment variable or use a default
c = os.getenv("MY_COLOR", "deepskyblue")
plt.style.use("_mpl-gallery")
# Generate random data
np.random.seed(21)
x = 4 + np.random.normal(0, 2, 24)
y = 4 + np.random.normal(0, 2, len(x))
sizes = np.random.uniform(15, 80, len(x))
opacity = np.random.uniform(0, 1, len(x))
# Create plot
fig, ax = plt.subplots()
ax.scatter(x, y, s=sizes * 30, color=c, alpha=opacity)
# Customize plot appearance
fig.set_size_inches(3, 3)
ax.set(
xlim=(0, 8), xticks=np.arange(1, 8),
ylim=(0, 8), yticks=np.arange(1, 8)
)
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment