plotting directl y u sing pandas
play

Plotting directl y u sing pandas P YTH ON FOR R U SE R S Daniel - PowerPoint PPT Presentation

Plotting directl y u sing pandas P YTH ON FOR R U SE R S Daniel Chen Instr u ctor Plotting in P y thon Q u ickl y sho w data pa erns Plo ing methods in P y thon : Pandas Seaborn Matplotlib PYTHON FOR R USERS Pandas plot method


  1. Plotting directl y u sing pandas P YTH ON FOR R U SE R S Daniel Chen Instr u ctor

  2. Plotting in P y thon Q u ickl y sho w data pa � erns Plo � ing methods in P y thon : Pandas Seaborn Matplotlib PYTHON FOR R USERS

  3. Pandas plot method plot() method hist : histogram box : bo x plot Works on the pandas kde : Kernel Densit y DataFrame and Series objects Estimation plot Pass plot the kind density : same as ‘ kde ’ arg u ment area : area plot kind of plots : pie : pie plot line : line plot ( defa u lt ) scatter : sca � er plot bar : v ertical bar plot hexbin : he x bin plot barh : hori z ontal bar plot PYTHON FOR R USERS

  4. Uni v ariate : Histogram import matplotlib.pyplot as plt iris['sepal_length'].plot(kind='hist') plt.show() PYTHON FOR R USERS

  5. Uni v ariate : Bar plot cts = iris['species'].value_counts() cts.plot(kind='bar') plt.show() PYTHON FOR R USERS

  6. Bi v ariate : Scatter plot iris.plot(kind='scatter', x='Sepal.Length', y='Sepal.Width' plt.show() PYTHON FOR R USERS

  7. Bi v ariate : Bo x plots iris.plot(kind='box') plt.show() PYTHON FOR R USERS

  8. Bi v ariate : Bo x plots iris.boxplot(by='Species', column='Sepal.Length') plt.show() PYTHON FOR R USERS

  9. Let ' s practice ! P YTH ON FOR R U SE R S

  10. Seaborn P YTH ON FOR R U SE R S Daniel Chen Instr u ctor

  11. Seaborn barplots : barplot histograms : displot bo x plot : boxplot sca � er plot : regplot Seaborn bene � ts colored points b y data facet plots b y data PYTHON FOR R USERS

  12. Seaborn histograms import seaborn as sns import matplotlib.pyplot as plt sns.distplot(iris['sepal_length']) plt.show() PYTHON FOR R USERS

  13. Seaborn co u nt plot sns.countplot('species', data=iris) plt.show() PYTHON FOR R USERS

  14. Seaborn bo x plots sns.boxplot(x='species', y='sepal_length', data=iris) plt.show() PYTHON FOR R USERS

  15. Seaborn scatterplots sns.regplot(x='sepal_length', y='sepal_width', data=iris) plt.show() PYTHON FOR R USERS

  16. Seaborn scatterplots w/ o u t regression line sns.regplot(x='sepal_length', y='sepal_width', data=iris, fit_reg=False) plt.show() PYTHON FOR R USERS

  17. Seaborn facets sns.lmplot(x='sepal_length', y='sepal_width', data=iris, fit_reg=False, col='species') plt.show() PYTHON FOR R USERS

  18. Seaborn FacetGrid g = sns.FacetGrid(iris, col="species") g = g.map(plt.hist, "sepal_length") plt.show() PYTHON FOR R USERS

  19. Let ' s practice ! P YTH ON FOR R U SE R S

  20. Matplotlib P YTH ON FOR R U SE R S Daniel Chen Instr u ctor

  21. Matplotlib plots import matplotlib.pyplot as plt plt.hist(iris['sepal_length']) plt.show() PYTHON FOR R USERS

  22. Matplotlib scatter plt.scatter(iris['sepal_length'], iris['sepal_width']) plt.show() PYTHON FOR R USERS

  23. Polishing u p the fig u re fig, ax = plt.subplots() ax.scatter(iris['sepal_length'], iris['sepal_width']) ax.set_title('Sepal Length') ax.set_xlabel('Sepal Length') ax.set_ylabel('Sepal Width') plt.show() PYTHON FOR R USERS

  24. Rotating a x is ticks fig, ax = plt.subplots() ax.scatter(iris['sepal_length'], iris['sepal_width']) ax.set_title('Sepal Length') ax.set_xlabel('Sepal Length') ax.set_ylabel('Sepal Width') plt.xticks(rotation=45) # rotate the x-axis ticks plt.show() PYTHON FOR R USERS

  25. Parts of a matplotlib fig u re PYTHON FOR R USERS

  26. Parts of a matplotlib fig u re 2 PYTHON FOR R USERS

  27. Fig u res and a x es fig, ax = plt.subplots() ax.scatter(iris['sepal_length'], iris['sepal_width']) plt.show() PYTHON FOR R USERS

  28. M u ltiple a x es fig, (ax1, ax2) = plt.subplots(1, 2) ax1.scatter(iris['sepal_length'], iris['sepal_width']) ax2.hist(iris['sepal_length']) plt.show() PYTHON FOR R USERS

  29. Remember fig, ax = plt.subplots() sns.regplot(x='sepal_length', y='sepal_width', data=iris, fit_reg=False, ax=ax) plt.show() PYTHON FOR R USERS

  30. Clearing the fig u re fig, (ax1, ax2) = plt.subplots(1, 2) ax1.scatter(iris['sepal_length'], iris['sepal_width']) ax2.hist(iris['sepal_length']) plt.show() plt.clf() PYTHON FOR R USERS

  31. Let ' s practice ! P YTH ON FOR R U SE R S

Recommend


More recommend