Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. # Imports
  2. import numpy as np
  3. from sklearn.datasets import make_blobs
  4. import matplotlib.pyplot as plt
  5. plt.xkcd();
  6. import seaborn as sns
  7. sns.set_style('white')
  8. # Set transparency off when exporting / Only if you want to save the figure
  9. from matplotlib import patheffects, rcParams
  10. rcParams['path.effects'] = [patheffects.withStroke(linewidth=0)]
  11. # Set font
  12. font = {'family' : 'Caveat',
  13. 'size' : 14}
  14. plt.rc('font', **font)
  15.  
  16. # Make sure its the same dataset
  17. np.random.seed(42*42)
  18.  
  19. # Generate data from scikit learn make_blobs
  20. # Here it would also work to create a two-dimensional dataset,
  21. # for my purpose a slice through six-dimensional blobs gave better results
  22. X, y = make_blobs(n_samples=200, centers=2, n_features=6, cluster_std=3.5)
  23. X = X.astype(np.float32)
  24.  
  25. # Plot data with matplotlib
  26. plt.plot(X[y>0,0], X[y>0,1], 'C0o')
  27. plt.plot(X[y<1,0]*-1, X[y<1,1], 'C1o')
  28. plt.legend(['Swedish', 'Norwegian'], loc='lower right', title='Nationality')
  29. plt.xlabel('Alcohol expenses', fontsize=18)
  30. plt.ylabel('Brunost consumption', fontsize=18)
  31. plt.gca().set_xticks([-9.,-4.,1.,6.,11.,16.])
  32. plt.gca().set_xticklabels([0,500,1000,1500,2000,2500])
  33. plt.gca().set_yticklabels([0,0,1,2,3,4,5,6,7])
  34. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement