preparing y o u r fig u res to share w ith others
play

Preparing y o u r fig u res to share w ith others IN TR OD U C TION - PowerPoint PPT Presentation

Preparing y o u r fig u res to share w ith others IN TR OD U C TION TO DATA VISU AL IZATION W ITH MATP L OTL IB Ariel Rokem Data Scientist Changing plot st y le import matplotlib.pyplot as plt fig, ax = plt.subplots()


  1. Preparing y o u r fig u res to share w ith others IN TR OD U C TION TO DATA VISU AL IZATION W ITH MATP L OTL IB Ariel Rokem Data Scientist

  2. Changing plot st y le import matplotlib.pyplot as plt fig, ax = plt.subplots() ax.plot(seattle_weather["MONTH"], seattle_weather["MLY-TAVG-NORMAL" ax.plot(austin_weather["MONTH"], austin_weather["MLY-TAVG-NORMAL"]) ax.set_xlabel("Time (months)") ax.set_ylabel("Average temperature (Fahrenheit degrees)") plt.show() INTRODUCTION TO DATA VISUALIZATION WITH MATPLOTLIB

  3. Choosing a st y le plt.style.use("ggplot") fig, ax = plt.subplots() ax.plot(seattle_weather["MONTH"], seattle_weather["MLY-TAVG-NORMAL" ax.plot(austin_weather["MONTH"], austin_weather["MLY-TAVG-NORMAL"]) ax.set_xlabel("Time (months)") ax.set_ylabel("Average temperature (Fahrenheit degrees)") plt.show() INTRODUCTION TO DATA VISUALIZATION WITH MATPLOTLIB

  4. Back to the defa u lt plt.style.use("default") INTRODUCTION TO DATA VISUALIZATION WITH MATPLOTLIB

  5. The a v ailable st y les h � ps :// matplotlib . org / galler y/ st y le _ sheets / st y le _ sheets _ refere INTRODUCTION TO DATA VISUALIZATION WITH MATPLOTLIB

  6. The " bmh " st y le plt.style.use("bmh") fig, ax = plt.subplots() ax.plot(seattle_weather["MONTH"], seattle_weather["MLY-TAVG-NORMAL" ax.plot(austin_weather["MONTH"], austin_weather["MLY-TAVG-NORMAL"]) ax.set_xlabel("Time (months)") ax.set_ylabel("Average temperature (Fahrenheit degrees)") plt.show() INTRODUCTION TO DATA VISUALIZATION WITH MATPLOTLIB

  7. Seaborn st y les plt.style.use("seaborn-colorblind") fig, ax = plt.subplots() ax.plot(seattle_weather["MONTH"], seattle_weather["MLY-TAVG-NORMAL" ax.plot(austin_weather["MONTH"], austin_weather["MLY-TAVG-NORMAL"]) ax.set_xlabel("Time (months)") ax.set_ylabel("Average temperature (Fahrenheit degrees)") plt.show() INTRODUCTION TO DATA VISUALIZATION WITH MATPLOTLIB

  8. G u idelines for choosing plotting st y le Dark backgro u nds are u s u all y less v isible If color is important , consider choosing colorblind - friendl y options " seaborn - colorblind " or " tablea u- colorblind 10" If y o u think that someone w ill w ant to print y o u r � g u re , u se less ink If it w ill be printed in black - and -w hite , u se the " gra y scale " st y le INTRODUCTION TO DATA VISUALIZATION WITH MATPLOTLIB

  9. Practice choosing the right st y le for y o u! IN TR OD U C TION TO DATA VISU AL IZATION W ITH MATP L OTL IB

  10. Sharing y o u r v is u ali z ations w ith others IN TR OD U C TION TO DATA VISU AL IZATION W ITH MATP L OTL IB Ariel Rokem Data Scientist

  11. A fig u re to share fig, ax = plt.subplots() ax.bar(medals.index, medals["Gold"]) ax.set_xticklabels(medals.index, rotation=90) ax.set_ylabel("Number of medals") plt.show() INTRODUCTION TO DATA VISUALIZATION WITH MATPLOTLIB

  12. Sa v ing the fig u re to file fig, ax = plt.subplots() ax.bar(medals.index, medals["Gold"]) ax.set_xticklabels(medals.index, rotation=90) ax.set_ylabel("Number of medals") fig.savefig("gold_medals.png") ls gold_medals.png INTRODUCTION TO DATA VISUALIZATION WITH MATPLOTLIB

  13. Different file formats fig.savefig("gold_medals.jpg") fig.savefig("gold_medals.jpg", quality=50) fig.savefig("gold_medals.svg") INTRODUCTION TO DATA VISUALIZATION WITH MATPLOTLIB

  14. Resol u tion fig.savefig("gold_medals.png", dpi=300) INTRODUCTION TO DATA VISUALIZATION WITH MATPLOTLIB

  15. Si z e fig.set_size_inches([5, 3]) INTRODUCTION TO DATA VISUALIZATION WITH MATPLOTLIB

  16. Another aspect ratio fig.set_size_inches([3, 5]) INTRODUCTION TO DATA VISUALIZATION WITH MATPLOTLIB

  17. Practice sa v ing y o u r v is u ali z ations ! IN TR OD U C TION TO DATA VISU AL IZATION W ITH MATP L OTL IB

  18. A u tomating fig u res from data IN TR OD U C TION TO DATA VISU AL IZATION W ITH MATP L OTL IB Ariel Rokem Data Scientist

  19. Wh y a u tomate ? Ease and speed Fle x ibilit y Rob u stness Reprod u cibilit y INTRODUCTION TO DATA VISUALIZATION WITH MATPLOTLIB

  20. Ho w man y different kinds of data ? summer_2016_medals["Sport"] ID 62 Rowing 65 Taekwondo 73 Handball ... 134759 Handball 135132 Volleyball 135205 Boxing Name: Sport, Length: 976, dtype: object INTRODUCTION TO DATA VISUALIZATION WITH MATPLOTLIB

  21. Getting u niq u e v al u es of a col u mn sports = summer_2016_medals["Sport"].unique() print(sports) ['Rowing' 'Taekwondo' 'Handball' 'Wrestling' 'Gymnastics' 'Swimming' 'Basketball' 'Boxing' 'Volleyball' 'Athletics'] INTRODUCTION TO DATA VISUALIZATION WITH MATPLOTLIB

  22. Bar - chart of heights for all sports fig, ax = plt.subplots() for sport in sports: sport_df = summer_2016_medals[summer_2016_medals["Sport"] == spor ax.bar(sport, sport_df["Height"].mean(), yerr=sport_df["Height"].std()) ax.set_ylabel("Height (cm)") ax.set_xticklabels(sports, rotation=90) plt.show() INTRODUCTION TO DATA VISUALIZATION WITH MATPLOTLIB

  23. Fig u re deri v ed a u tomaticall y from the data INTRODUCTION TO DATA VISUALIZATION WITH MATPLOTLIB

  24. Practice a u tomating v is u ali z ations ! IN TR OD U C TION TO DATA VISU AL IZATION W ITH MATP L OTL IB

  25. Where to go ne x t IN TR OD U C TION TO DATA VISU AL IZATION W ITH MATP L OTL IB Ariel Rokem Data Scientist

  26. The Matplotlib galler y h � ps :// matplotlib . org / galler y. html INTRODUCTION TO DATA VISUALIZATION WITH MATPLOTLIB

  27. Galler y of e x amples INTRODUCTION TO DATA VISUALIZATION WITH MATPLOTLIB

  28. E x ample page w ith code INTRODUCTION TO DATA VISUALIZATION WITH MATPLOTLIB

  29. Plotting data in 3 D h � ps :// matplotlib . org / mpl _ toolkits / mplot 3 d / t u torial . html INTRODUCTION TO DATA VISUALIZATION WITH MATPLOTLIB

  30. Vis u ali z ing images w ith pse u do - color h � ps :// matplotlib . org /u sers / image _ t u torial . html INTRODUCTION TO DATA VISUALIZATION WITH MATPLOTLIB

  31. Animations Image credit : G y tis D u das and Andre w Ramba u t h � ps :// matplotlib . org / api / animation _ api . html INTRODUCTION TO DATA VISUALIZATION WITH MATPLOTLIB

  32. Using Matplotlib for geospatial data h � ps :// scitools . org .u k / cartop y/ docs / latest / INTRODUCTION TO DATA VISUALIZATION WITH MATPLOTLIB

  33. Pandas + Matplotlib = Seaborn seaborn.relplot(x="horsepower", y="mpg", hue="origin", size="weight sizes=(40, 400), alpha=.5, palette="muted", height=6, data=mpg) INTRODUCTION TO DATA VISUALIZATION WITH MATPLOTLIB

  34. Seaborn e x ample galler y h � ps :// seaborn . p y data . org / e x amples / inde x. html INTRODUCTION TO DATA VISUALIZATION WITH MATPLOTLIB

  35. Good l u ck v is u ali z ing y o u r data ! IN TR OD U C TION TO DATA VISU AL IZATION W ITH MATP L OTL IB

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