plotting m u ltiple graphs
play

Plotting m u ltiple graphs IN TR OD U C TION TO DATA VISU AL - PowerPoint PPT Presentation

Plotting m u ltiple graphs IN TR OD U C TION TO DATA VISU AL IZATION IN P YTH ON Br y an Van de Ven Core De v eloper of Bokeh Strategies Plo ing man y graphs on common a x es Creating a x es w ithin a g u re Creating s u bplots w ithin


  1. Plotting m u ltiple graphs IN TR OD U C TION TO DATA VISU AL IZATION IN P YTH ON Br y an Van de Ven Core De v eloper of Bokeh

  2. Strategies Plo � ing man y graphs on common a x es Creating a x es w ithin a � g u re Creating s u bplots w ithin a � g u re INTRODUCTION TO DATA VISUALIZATION IN PYTHON

  3. Graphs on common a x es import matplotlib.pyplot as plt plt.plot(t, temperature, 'r') # Appears on same axes plt.plot(t, dewpoint, 'b') plt.xlabel('Date') plt.title('Temperature & Dew Point') # Renders plot objects to screen plt.show() INTRODUCTION TO DATA VISUALIZATION IN PYTHON

  4. Using a x es () plt.axes([0.05,0.05,0.425,0.9]) plt.plot(t, temperature, 'r') plt.xlabel('Date') plt.title('Temperature') plt.axes([0.525,0.05,0.425,0.9]) plt.plot(t, dewpoint, 'b') plt.xlabel('Date') plt.title('Dew Point') plt.show() INTRODUCTION TO DATA VISUALIZATION IN PYTHON

  5. The a x es () command S y nta x: axes( [x_lo, y_lo, width, height] ) Units bet w een 0 and 1 (� g u re dimensions ) INTRODUCTION TO DATA VISUALIZATION IN PYTHON

  6. Using s u bplot () INTRODUCTION TO DATA VISUALIZATION IN PYTHON

  7. Using s u bplot () plt.subplot(2, 1, 1) plt.plot(t, temperature, 'r') plt.xlabel('Date') plt.title('Temperature') plt.subplot(2, 1, 2) plt.plot(t, dewpoint, 'b') plt.xlabel('Date') plt.title('Dew Point') plt.tight_layout() plt.show() INTRODUCTION TO DATA VISUALIZATION IN PYTHON

  8. The s u bplot () command S y nta x: subplot(nrows, ncols, nsubplot) S u bplot ordering : Ro w-w ise from top le � Inde x ed from 1 INTRODUCTION TO DATA VISUALIZATION IN PYTHON

  9. Let ' s practice ! IN TR OD U C TION TO DATA VISU AL IZATION IN P YTH ON

  10. C u stomi z ing a x es IN TR OD U C TION TO DATA VISU AL IZATION IN P YTH ON Br y an Van de Ven Core De v eloper of Bokeh

  11. Controlling a x is e x tents axis([xmin, xmax, ymin, ymax]) sets a x is e x tents Control o v er indi v id u al a x is e x tents xlim([xmin, xmax]) ylim([ymin, ymax]) Can u se t u ples , lists for e x tents e . g ., xlim((-2, 3)) w orks e . g ., xlim([-2, 3]) w orks also INTRODUCTION TO DATA VISUALIZATION IN PYTHON

  12. GDP o v er time import matplotlib.pyplot as plt plt.plot(yr, gdp) plt.xlabel('Year') plt.ylabel('Billions of Dollars') plt.title('US Gross Domestic Product') plt.show() INTRODUCTION TO DATA VISUALIZATION IN PYTHON

  13. Using x lim () plt.plot(yr, gdp) plt.xlabel('Year') plt.ylabel('Billions of Dollars') plt.title('US Gross Domestic Product') plt.xlim((1947, 1957)) plt.show() INTRODUCTION TO DATA VISUALIZATION IN PYTHON

  14. Using x lim () and y lim () plt.plot(yr, gdp) plt.xlabel('Year') plt.ylabel('Billions of Dollars') plt.title('US Gross Domestic Product') plt.xlim((1947, 1957)) plt.ylim((0, 1000)) plt.show() INTRODUCTION TO DATA VISUALIZATION IN PYTHON

  15. Using a x is () plt.plot(yr, gdp) plt.xlabel('Year') plt.ylabel('Billions of Dollars') plt.title('US Gross Domestic Product') plt.axis((1947, 1957, 0, 600)) plt.show() INTRODUCTION TO DATA VISUALIZATION IN PYTHON

  16. Other a x is () options In v ocation Res u lt axis('off') t u rns o � a x is lines , labels axis('equal') eq u al scaling on x and y a x es axis('square') forces sq u are plot axis('tight') sets xlim , ylim to sho w all data INTRODUCTION TO DATA VISUALIZATION IN PYTHON

  17. Using a x is (' eq u al ') INTRODUCTION TO DATA VISUALIZATION IN PYTHON

  18. Using a x is (' eq u al ') plt.subplot(2, 1, 1) plt.plot(x, y, 'red') plt.title('default axis') plt.subplot(2, 1, 2) plt.plot(x, y, 'red') plt.axis('equal') plt.title('axis equal') plt.tight_layout() plt.show() INTRODUCTION TO DATA VISUALIZATION IN PYTHON

  19. Let ' s practice ! IN TR OD U C TION TO DATA VISU AL IZATION IN P YTH ON

  20. Legends , annotations , and st y les IN TR OD U C TION TO DATA VISU AL IZATION IN P YTH ON Br y an Van de Ven Core De v eloper of Bokeh

  21. Legends Legend pro v ide labels for o v erlaid points and c u r v es INTRODUCTION TO DATA VISUALIZATION IN PYTHON

  22. Using legend () import matplotlib.pyplot as plt plt.scatter(setosa_len, setosa_wid, marker='o', color='red', label='setosa') plt.scatter(versicolor_len, versicolor_wid, marker='o', color='green', label='versicolor') plt.scatter(virginica_len, virginica_wid, marker='o', color='blue', label='virginica') plt.legend(loc='upper right') plt.title('Iris data') plt.xlabel('sepal length (cm)') plt.ylabel('sepal width (cm)') plt.show() INTRODUCTION TO DATA VISUALIZATION IN PYTHON

  23. Legend locations string code string code 'upper left' 'upper right' 2 1 'center left' 'center right' 6 7 'lower left' 'lower right' 3 4 'upper center' 'right' 9 5 'center' 'best' 10 0 'lower center' 8 INTRODUCTION TO DATA VISUALIZATION IN PYTHON

  24. Plot annotations Te x t labels and arro w s u sing annotate() method Fle x ible speci � cation of coordinates Ke yw ord arrowprops : dict of arro w properties width color etc . INTRODUCTION TO DATA VISUALIZATION IN PYTHON

  25. Using annotate () for te x t plt.annotate('setosa', xy=(5.0, 3.5)) plt.annotate('virginica', xy=(7.25, 3.5)) plt.annotate('versicolor', xy=(5.0, 2.0)) plt.show() INTRODUCTION TO DATA VISUALIZATION IN PYTHON

  26. Options for annotate () option description s te x t of label xy coordinates to annotate xytext coordinates of label arrowprops controls dra w ing of arro w INTRODUCTION TO DATA VISUALIZATION IN PYTHON

  27. Using annotate () for arro w s INTRODUCTION TO DATA VISUALIZATION IN PYTHON

  28. Using annotate () for arro w s plt.annotate('setosa', xy=(5.0, 3.5), xytext=(4.25, 4.0), arrowprops={'color':'red'}) plt.annotate('virginica', xy=(7.2, 3.6), xytext=(6.5, 4.0), arrowprops={'color':'blue'}) plt.annotate('versicolor', xy=(5.05, 1.95), xytext=(5.5, 1.75), arrowprops={'color':'green'}) plt.show() INTRODUCTION TO DATA VISUALIZATION IN PYTHON

  29. Working w ith plot st y les St y le sheets in matplotlib Defa u lts for lines , points , backgro u nds , etc . S w itch st y les globall y w ith plt.style.use() plt.style.available : list of st y les INTRODUCTION TO DATA VISUALIZATION IN PYTHON

  30. ggplot st y le import matplotlib.pyplot as plt plt.style.use('ggplot') INTRODUCTION TO DATA VISUALIZATION IN PYTHON

  31. fi v ethirt y eight st y le import matplotlib.pyplot as plt plt.style.use('fivethirtyeight') INTRODUCTION TO DATA VISUALIZATION IN PYTHON

  32. Let ' s practice ! IN TR OD U C TION TO DATA VISU AL IZATION IN P YTH ON

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend