You Need to Have Flexible Thinking when Programming
Don't think about one perfect solution. Instead, start thinking about choosing an option out of the many you have to solve problems.
If you are trying to solve a problem with programming, you may have several solutions to get the same result.
A basic idea that we don't get at the beginning because we look for that perfect solution.
It doesn’t exist.
It would be best to start thinking about choosing the "one" option, not "the" option.
Let’s say that we are facing the following problem: visualise two variables with a scatterplot.
import pandas as pd
df = pd.read_csv('https://raw.githubusercontent.com/mwaskom/seaborn-data/master/tips.csv')
df.head()
In Python, you’ve got 3 libraries that can make a scatterplot
:
matplotlib
seaborn
plotly
Let’s observe the differences:
Matplotlib
import matplotlib.pyplot as plt
plt.scatter(x='total_bill', y='tip', data=df)
Seaborn
import seaborn as sns
sns.scatterplot(x='total_bill', y='tip', data=df)
Plotly
import plotly.express as px
px.scatter(data_frame=df, x='total_bill', y='tip')
Takeaways
matplotlib
allows you to create custom plots, but you need to write more code.seaborn
automates the plot so that you don’t need to write more lines. For example,seaborn
added the x & y axis labels by default.matplotlib
didn’t.plotly
allows you to interact with the plot. Give it a try and hover the mouse over the points.
If you are to make a plot for an online post, you may like to use plotly
due to its interactivity. Nevertheless, you wouldn’t use it if you were writing a paper article.
I teach Python, R, Statistics & Data Science. I like to produce content that helps people to understand these topics better.
Feel free and welcomed to give me feedback as I would like to make my tutorials clearer and generate content that interests you 🤗
You can see my Tutor Profile here if you need Private Tutoring lessons.