#!/usr/bin/env python # coding: utf-8 # ## Plotting with plot.ly backend # In[1]: # 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. # In[2]: import plotly.offline as po po.init_notebook_mode() # In[3]: # Define the 1-D example H = normal_h1() # The default plot is `bar`. # In[4]: H.plot() # Same as H.plot.bar() # In[5]: H.plot.line() # In[6]: H.plot.scatter() # ## Matplotlib compatibility # # 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: # In[7]: H.plot.line(color="red", lw=5, yscale="log", mpl=True) # ## Plot.ly object # # If you want to further manipulate the figures, you can return them from # the function as-is using the `raw` keyword. # In[8]: H.plot.scatter(raw=True) # ## 2D histograms # In[9]: H2 = normal_h2() # In[10]: # Default is heatmap H2.plot() # ## Collections # In[11]: 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") # In[12]: collection.plot.line() # In[13]: # Let's see normalized histograms in the collection collection.normalize_bins().plot(barmode="overlay", alpha=0.3) # In[14]: # ...and how they look like when stacked collection.normalize_bins().plot(barmode="stack")