Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.25 KB | None | 0 0
  1. """
  2. FacetGrid Plot Showing Overlapping Distributions (Densities) Offset by ('ridge plot')
  3. ====================================
  4. """
  5. import numpy as np
  6. import pandas as pd
  7. import seaborn as sns
  8. import matplotlib.pyplot as plt
  9. sns.set(style="white", rc={"axes.facecolor": (0, 0, 0, 0)})
  10.  
  11. # Create some random distribution data and labels, and store them in a dataframe
  12. rs = np.random.RandomState(1979)
  13. x = rs.randn(500)
  14. g = np.tile(list("ABCDEFGHIJ"), 50)
  15. df = pd.DataFrame(dict(x=x, g=g))
  16. m = df.g.map(ord)
  17. df["x"] += m
  18.  
  19. # Initialize the FacetGrid chart object
  20. pal = sns.cubehelix_palette(10, rot=-.25, light=.7)
  21. g = sns.FacetGrid(df, row="g", hue="g", aspect=15, height=.5, palette=pal)
  22.  
  23. # Draw the densities in a few steps
  24. g.map(sns.kdeplot, "x", clip_on=False, shade=True, alpha=1, lw=1.5, bw=.2)
  25. g.map(sns.kdeplot, "x", clip_on=False, color="w", lw=2, bw=.2)
  26. g.map(plt.axhline, y=0, lw=2, clip_on=False)
  27.  
  28.  
  29. # Define and use a simple function to label the plot in axes coordinates
  30. def label(x, color, label):
  31. ax = plt.gca()
  32. ax.text(0, .2, label, fontweight="bold", color=color,
  33. ha="left", va="center", transform=ax.transAxes)
  34.  
  35. # Use ``map()`` to calculate the label positions
  36. g.map(label, "x")
  37.  
  38. # Set the subplots to overlap slightly on their vertical direction
  39. g.fig.subplots_adjust(hspace=-.3)
  40.  
  41. # Remove axes details that don't play well with overlap
  42. g.set_titles("")
  43. g.set(yticks=[])
  44. g.despine(bottom=True, left=True)
  45. g.fig.subplots(figsize=(12,12)) # Don't know how to change figure size for a set of overlapping Seaborn plots
  46.  
  47. self.fig.tight_layout()
  48. C:Anaconda3libsite-packagesseabornaxisgrid.py:848: UserWarning: Tight layout not applied. tight_layout cannot make axes height small enough to accommodate all axes decorations
  49. self.fig.tight_layout()
  50. C:Anaconda3libsite-packagesseabornaxisgrid.py:848: UserWarning: Tight layout not applied. tight_layout cannot make axes height small enough to accommodate all axes decorations
  51. self.fig.tight_layout()
  52.  
  53. <ipython-input-25-a661dbef6e83> in <module>
  54. 43 g.set(yticks=[])
  55. 44 g.despine(bottom=True, left=True)
  56. ---> 45 g.fig.subplots(size=(12,12)) # Don't know how to change figure size for a set of overlapping Seaborn plots
  57.  
  58. TypeError: subplots() got an unexpected keyword argument 'size'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement