Plotting physt histograms

Some matplotlib-based plotting examples, with no exhaustive documentation.


In [1]:
# Necessary import evil
import physt
from physt import h1, h2, histogramdd
from physt.plotting import matplotlib
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline

np.random.seed(42)

from physt import plotting

In [2]:
# Some data
x = np.random.normal(100, 1, 10000)
y = np.random.normal(10, 10, 10000)

In [3]:
ax = h2(x, y, 15).plot(figsize=(6, 6), show_zero=False, alpha=0, text_color="black", show_values=True, cmap="BuGn_r", show_colorbar=False, transform=lambda x:1)
h2(x, y, 50).plot.image(cmap="Spectral_r", alpha=0.75, ax=ax)


Out[3]:
<matplotlib.axes._subplots.AxesSubplot at 0x7f65849404e0>

In [4]:
h2(x, y, 40, name="Gauss").plot("image", cmap="rainbow", figsize=(5, 5))


Out[4]:
<matplotlib.axes._subplots.AxesSubplot at 0x7f65845d18d0>

In [5]:
plotting.matplotlib.bar3d(h2(x, y, 10, name="Gauss"), figsize=(5, 5), cmap="Accent");



In [6]:
h1(x, "human", 10, name="Gauss").plot(ylim=(100, 1020), cmap="Greys", ticks="edge", errors=True);



In [7]:
h1(x, "human", 200, name="Gauss").plot.line(errors=True, yscale="log")


Out[7]:
<matplotlib.axes._subplots.AxesSubplot at 0x7f65826b1668>

In [8]:
h1(x, "human", 200, name="Gauss").plot.fill(lw=1, alpha=.4, figsize=(8, 4))
h1(x, "human", 200, name="Gauss").plot.fill(lw=1, alpha=.4, yscale="log", figsize=(8, 4), color="red")


Out[8]:
<matplotlib.axes._subplots.AxesSubplot at 0x7f6582772400>

In [9]:
h1(x, "human", 200, name="Gauss").plot.scatter(errors=True, xlim=(90, 100), show_stats="all")


Out[9]:
<matplotlib.axes._subplots.AxesSubplot at 0x7f658305cd68>

In [10]:
ha = h1(x, "human", 20, name="Left")
hb = h1(x + 1 * np.sin(x / 12), "human", 40, name="Right")

from physt.plotting.matplotlib import pair_bars

In [11]:
pair_bars(ha, hb, density=True, errors=True, figsize=(5, 5));


Example - histogram of time values


In [12]:
# Get values close to 
from physt.plotting.common import TimeTickHandler

data = np.random.normal(3600, 900, 4800)
H = h1(data, "human", axis_name="time")
H.plot(tick_handler=TimeTickHandler())


Out[12]:
<matplotlib.axes._subplots.AxesSubplot at 0x7f65824ffbe0>