示例#1
0
"""
Nested pie chart
================
An example of a nested pie chart.
"""
import matplotlib.pyplot as plt
from niceplots import setRCParams, plotNestedPie

setRCParams()

data = {
    "Pie": {
        "Lime": 5,
        "Apple": 8,
        "Cow": 3,
    },
    "Not pie": {
        "Taco": 5,
        "Soup": 4,
    },
    "Pizza": {
        "Cheese": 14,
        "White": 5,
        "Veggie": 12,
    },
}

# Custom colors
colors = ["#e86492", "#f0a43a", "#56b2f0"]

fig, ax = plt.subplots(figsize=(13, 8))
示例#2
0
"""
Stacked plots
=============
An example of a stacked plot.
"""

import numpy as np
import matplotlib.pyplot as plt
import niceplots

niceplots.setRCParams()

# Set the random seed to get consistent results.
np.random.seed(314)

# Create some fake data to plot.
# Time will be the x-axis, position and velocity of a damped oscilator will be two plots stacked on top of each other
# for the y-axes.
nn = 30
n_lines = 4
phases = np.random.random_sample(n_lines) * 2.0 * np.pi
damping = -np.random.random_sample(n_lines) * 2.0 * 250.0
time = np.linspace(0, 250.0, nn)
data = []

for phase, damp in zip(phases, damping):
    Position = 1.0 + np.sin(2 * np.pi * time / 100 + phase) * np.exp(time / damp)
    Velocity = 2 * np.pi / 100 * np.cos(2 * np.pi * time / 100 + phase) * np.exp(time / damp)

    data.append({})
    data[-1]["Position (m)"] = Position
示例#3
0
# Standard Python modules
# ==============================================================================

# ==============================================================================
# External Python modules
# ==============================================================================
import numpy as np
import matplotlib.pyplot as plt
import niceplots

# ==============================================================================
# Extension modules
# ==============================================================================

# Dark mode with a transparent background, saved to a png
niceplots.setRCParams(dark_mode=True)

x = np.linspace(0, 2 * np.pi, 100)
y = np.sin(x)
c = np.cos(x)

fig, ax = plt.subplots()
niceplots.plotColoredLine(x,
                          y,
                          c,
                          cmap="coolwarm",
                          fig=fig,
                          ax=ax,
                          addColorBar=True,
                          cRange=None,
                          cBarLabel="$dy/dx$")