Data Visualization & Storytelling in Python Flashcards
This covers various data visualization in Python
What Python libraries are commonly used for data visualization?
- Matplotlib
- Seaborn
- Plotly
- ggplot
- Altair
Each library has strengths depending on the use case.
What is Matplotlib?
A low-level visualization library for creating static, animated, and interactive plots.
It provides full control over plot appearance.
What is Seaborn built on?
Matplotlib
Seaborn simplifies statistical visualizations.
What command in Matplotlib is used to create a basic line plot?
plt.plot()
Part of Matplotlib’s pyplot module.
Fill in the blank:
plt.show() is used to ____ in Matplotlib.
Display the figure.
Without plt.show(), plots may not render properly in some environments.
How do you import Seaborn?
import seaborn as sns
The alias sns is commonly used.
How do you load a built-in Seaborn dataset?
sns.load_dataset(“dataset_name”)
Example: sns.load_dataset(“iris”)
What is the default style of Seaborn?
darkgrid
Seaborn styles improve readability.
What function is used to create a histogram in Seaborn?
sns.histplot()
Histograms help visualize distributions.
How do you change the figure size in Matplotlib?
plt.figure(figsize=(width, height))
Helps with readability.
Which function is used to create a scatter plot in Matplotlib?
plt.scatter(x, y)
Scatter plots show relationships between two numerical variables.
What is the difference between sns.histplot() and sns.kdeplot()?
histplot() shows bar-like frequency, while kdeplot() smooths it into a curve.
KDE plots estimate probability distributions.
How do you create a box plot in Seaborn?
sns.boxplot(x=”column”, data=df)
Box plots show distributions and outliers.
What does a violin plot add compared to a box plot?
It shows kernel density estimation (KDE) along with quartiles.
sns.violinplot() is used for this.
What function is used to create a bar chart in Seaborn?
sns.barplot(x=”category”, y=”value”, data=df)
Used for categorical comparisons.
What is the main advantage of using Plotly over Matplotlib?
Plotly supports interactivity.
Good for dashboards and dynamic exploration.
Which function in Plotly is used for line plots?
px.line(df, x=”column_x”, y=”column_y”)
px is short for plotly.express.
What is the main difference between sns.barplot() and sns.countplot()?
barplot()requires numerical y-values, while countplot() works with categorical counts.
Count plots count occurrences automatically.
What is the purpose of ax.set_title(“Title”) in Matplotlib?
Adds a title to the plot.
Helps provide context.
How do you change the color palette in Seaborn?
sns.set_palette(“color_palette”)
Example: “pastel”, “muted”, “deep”.
What argument in Seaborn adjusts transparency?
alpha
Example: sns.scatterplot(x, y, alpha=0.5).
What does plt.savefig(“plot.png”) do?
Saves the plot as an image file.
Supports formats like PNG, JPG, SVG.
How do you add labels to the x-axis and y-axis in Matplotlib?
plt.xlabel(“X Label”), plt.ylabel(“Y Label”)
Labels are crucial for clarity.
What is the advantage of using tight_layout()?
Adjusts spacing automatically.
Prevents overlapping labels.