Skip to main content

Minimal, beautiful (+ highly-customizable) styles for Matplotlib.

Project description

ambivalent 🤷🏻‍♂️

Sam Foreman 2023-12-29

opinionated $\longrightarrow$ ambivalent

Clean, simple style for Matplotlib figures.

Transparent backgrounds with grey text $\textcolor{#838383}{\blacksquare}$ that are accessible / legible and {light, dark}-mode independent.

Examples[^1]

Figure 1: seborn.jointplot

Figure 2: spectrum

Figure 3: tips dataset

Figure 4: 2D KDE

Figure 5: Histograms

More Examples

Figure 6: |J_{f}|

Figure 7: |J_{b}|

Figure 8: |J|

Even more…

(a) \delta Q_{\mathrm{train}}

Figure 9: Figure from l2hmc-qcd Notebook

InferenceData

Figure 10: $\varepsilon_{x}$ during training

Figure 11: $\varepsilon_{x}$ during training

(a) \sum \delta Q

Figure 12: Figure from l2hmc-qcd Notebook

Getting Started

  • Use ambivalend.STYLES['ambivalent'] as the default style for matplotlib.
import matplotlib.pyplot as plt
from ambivalent import STYLES
plt.style.use(STYLES['ambivalent'])

seaborn Tips Dataset

View Code
import seaborn as sns

tips = sns.load_dataset("tips")
tips.head()

fig, ax = plt.subplots(figsize=(6, 6))  # , ncols=2)

_ = sns.kdeplot(
   data=tips, x="total_bill", hue="size",
   fill=True, common_norm=False, palette="flare_r",
   alpha=.3, linewidth=0,
   ax=ax,  # [0],
)
_ = ax.set_ylabel('')
# _ = sns.kdeplot(
#    data=tips, x="tip", hue="size",
#    fill=True, common_norm=False, palette="crest",
#    alpha=.3, linewidth=0,
#    ax=ax[1],
# )

Figure 13: Tips – Density Plot

seaborn Scatter Plot

View Code
import seaborn as sns
import matplotlib.pyplot as plt

# Load the example diamonds dataset
diamonds = sns.load_dataset("diamonds")

# Draw a scatter plot while assigning point colors and sizes to different
# variables in the dataset
f, ax = plt.subplots(figsize=(6, 6))
_ = sns.despine(f, left=True, bottom=True)
_ = clarity_ranking = ["I1", "SI2", "SI1", "VS2", "VS1", "VVS2", "VVS1", "IF"]
_ = sns.scatterplot(x="carat", y="price",
                hue="clarity", size="depth",
                palette="flare",
                hue_order=clarity_ranking,
                sizes=(1, 8), linewidth=0,
                data=diamonds, ax=ax)

Figure 14: scatter plot with markers of varying size and color

Histogram + Scatter Plot

View Code
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt

# Simulate data from a bivariate Gaussian
n = 10000
mean = [0, 0]
cov = [(2, .4), (.4, .2)]
rng = np.random.RandomState(0)
x, y = rng.multivariate_normal(mean, cov, n).T

# Draw a combo histogram and scatterplot with density contours
f, ax = plt.subplots(figsize=(6, 6))
_ = sns.scatterplot(x=x, y=y, s=5, color="#666666", alpha=0.3)
_ = sns.histplot(x=x, y=y, bins=50, pthresh=.1, cmap="flare_r")
_ = sns.kdeplot(x=x, y=y, levels=5, color="w", linewidths=1)
_ = ax.set_xlabel('x')
_ = ax.set_ylabel('y')
_ = plt.show()

Figure 15: Combo histogram + Scatter Plot with Density Contours

Jointplot

View Code
import seaborn as sns
# Load the penguins dataset
penguins = sns.load_dataset("penguins")
# Show the joint distribution using kernel density estimation
import matplotlib as mpl
with mpl.rc_context(plt.rcParams.update({'axes.grid': False})):
  g = sns.jointplot(
      data=penguins,
      x="bill_length_mm",
      y="bill_depth_mm",
      hue="species",
      # kind="kde",
      edgecolors='none',
      alpha=0.4,
  )
  _ = plt.grid(False)
  plt.show()

Figure 16: Joint Distribution with Kernel Density Estimation

Matplotlib Histograms

View Code
import matplotlib.pyplot as plt
import numpy as np

n_bins = 10
x = np.random.randn(1000, 3)

plt.rcParams['axes.grid'] = True

fig, ((ax0, ax1), (ax2, ax3)) = plt.subplots(nrows=2, ncols=2)

colors = ['#333333', '#666666', '#999999']
ax0.hist(x, n_bins, density=True, histtype='bar', color=colors, label=colors)
_ = ax0.legend()
_ = ax0.set_title('bars with legend')

_ = ax1.hist(x, n_bins, density=True, histtype='bar', stacked=True, alpha=0.4)
_ = ax1.set_title('stacked bar')

_ = ax2.hist(x, n_bins, histtype='step', stacked=True, fill=False)
_ = ax2.set_title('stack step (unfilled)')

# Make a multiple-histogram of data-sets with different length.
x_multi = [np.random.randn(n) for n in [10000, 5000, 2000]]
_ = ax3.hist(x_multi, n_bins, histtype='bar')
_ = ax3.set_title('different sample sizes')

_ = fig.tight_layout()
plt.show()

Figure 17: Histograms with Matplotlib

Status

Last Updated: 12/29/2023 @ 10:42:06

[^1]: Examples from Matplotlib Examples

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ambivalent-0.1.0.tar.gz (67.0 MB view hashes)

Uploaded Source

Built Distribution

ambivalent-0.1.0-py3-none-any.whl (26.7 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page