Created
December 15, 2024 20:31
-
-
Save kolibril13/750658068ee96e631dab00d1bc25e59b to your computer and use it in GitHub Desktop.
matplotlib with environment variables.
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
# /// script | |
# requires-python = ">=3.12" | |
# dependencies = [ | |
# "matplotlib", | |
# ] | |
# /// | |
# hearder was generated with command: | |
# uv add --script foo.py matplotlib | |
# run with command: | |
# MY_COLOR=red uv run foo.py | |
import matplotlib.pyplot as plt | |
import numpy as np | |
import os | |
# Set color from environment variable or use default | |
color = os.getenv("MY_COLOR", "deepskyblue") | |
# Generate random data | |
np.random.seed(21) | |
x, y = 4 + np.random.normal(0, 2, 24), 4 + np.random.normal(0, 2, 24) | |
sizes, opacity = np.random.uniform(15, 80, 24), np.random.uniform(0, 1, 24) | |
# Create and display plot | |
plt.style.use("_mpl-gallery") | |
fig, ax = plt.subplots(figsize=(3, 3)) | |
ax.scatter(x, y, s=sizes * 30, color=color, alpha=opacity) | |
ax.set(xlim=(0, 8), xticks=range(1, 8), ylim=(0, 8), yticks=range(1, 8)) | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
MY_COLOR=orange uv run https://gist.githubusercontent.com/kolibril13/750658068ee96e631dab00d1bc25e59b/raw/ecc002f8a0f5e14118941bf0f401c6db5518a053/foo.py