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() 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
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
Back to the defa u lt plt.style.use("default") INTRODUCTION TO DATA VISUALIZATION WITH MATPLOTLIB
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
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
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
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
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
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
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
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
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
Resol u tion fig.savefig("gold_medals.png", dpi=300) INTRODUCTION TO DATA VISUALIZATION WITH MATPLOTLIB
Si z e fig.set_size_inches([5, 3]) INTRODUCTION TO DATA VISUALIZATION WITH MATPLOTLIB
Another aspect ratio fig.set_size_inches([3, 5]) INTRODUCTION TO DATA VISUALIZATION WITH MATPLOTLIB
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
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
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
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
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
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
Fig u re deri v ed a u tomaticall y from the data INTRODUCTION TO DATA VISUALIZATION WITH MATPLOTLIB
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
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
The Matplotlib galler y h � ps :// matplotlib . org / galler y. html INTRODUCTION TO DATA VISUALIZATION WITH MATPLOTLIB
Galler y of e x amples INTRODUCTION TO DATA VISUALIZATION WITH MATPLOTLIB
E x ample page w ith code INTRODUCTION TO DATA VISUALIZATION WITH MATPLOTLIB
Plotting data in 3 D h � ps :// matplotlib . org / mpl _ toolkits / mplot 3 d / t u torial . html INTRODUCTION TO DATA VISUALIZATION WITH MATPLOTLIB
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
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
Using Matplotlib for geospatial data h � ps :// scitools . org .u k / cartop y/ docs / latest / INTRODUCTION TO DATA VISUALIZATION WITH MATPLOTLIB
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
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
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
Recommend
More recommend