# Basic imports
from physt.examples import normal_h2, normal_h1
from physt.plotting import plotly
import physt.plotting
import numpy as np
np.random.seed(42)
# Set that we want plotly
physt.plotting.set_default_backend("plotly")
The following lines are necessary if you want to display plots in the Jupyter notebook.
import plotly.offline as po
po.init_notebook_mode()
# Define the 1-D example
H = normal_h1()
The default plot is bar
.
H.plot() # Same as H.plot.bar()
H.plot.line()
H.plot.scatter()
Plot.ly supports to convert matplotlib figures into plot.ly ones. You can use this compatibility with several fancy properties.
Just add the mpl
keyword argument to your plotting call:
H.plot.line(color="red", lw=5, yscale="log", mpl=True)
If you want to further manipulate the figures, you can return them from
the function as-is using the raw
keyword.
H.plot.scatter(raw=True)
Figure({ 'data': [{'mode': 'markers', 'name': 'normal', 'type': 'scatter', 'uid': '2138449c-3e92-11e9-ba8b-3b7509a6e7b7', 'x': array([-3.52996835, -2.74510456, -1.96024076, -1.17537697, -0.39051317, 0.39435063, 1.17921442, 1.96407822, 2.74894201, 3.53380581]), 'y': array([ 10., 88., 485., 1605., 2831., 2844., 1543., 498., 88., 8.])}], 'layout': {} })
H2 = normal_h2()
# Default is heatmap
H2.plot()
from physt.histogram_collection import HistogramCollection
collection = HistogramCollection.h1({
"small": np.random.normal(160, 20, 600),
"tall": np.random.normal(180, 20, 1000),
"huge": np.random.normal(200, 20, 400),
"gigantic": np.random.normal(220, 20, 200)
}, "human")
collection.plot.line()
# Let's see normalized histograms in the collection
collection.normalize_bins().plot(barmode="overlay", alpha=0.3)
# ...and how they look like when stacked
collection.normalize_bins().plot(barmode="stack")