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.
What does plt.legend() do?
Adds a legend to the plot.
Legends help differentiate categories.
How do you create a correlation heatmap in Seaborn?
sns.heatmap(df.corr(), annot=True, cmap=”coolwarm”)
Heatmaps visualize correlations between variables.
What does hue do in Seaborn plots?
Adds color differentiation based on a categorical variable.
Example: sns.scatterplot(x, y, hue=”category”, data=df).
What function is used for facet grids in Seaborn?
sns.FacetGrid()
Creates multiple subplots for different categories.
What is the best visualization for time series data?
Line plot
sns.lineplot() is commonly used.
What are “small multiples” in data visualization?
Repeating the same chart for different subsets of data.
Helps in comparative analysis.
How do you rotate x-axis labels in Matplotlib?
plt.xticks(rotation=45)
Useful when dealing with long category names.
What does plt.subplots() do?
Creates multiple plots in a single figure.
Used for dashboards or comparisons.
How do you customize tick labels in Matplotlib?
plt.xticks(ticks, labels)
Helps improve readability.
What does sns.pairplot(df) do?
Plots pairwise relationships in the dataset.
Great for EDA and correlation analysis.
What is a bubble chart?
A scatter plot where point size represents a third variable.
Used in business analytics.
What does plt.grid(True) do?
Adds gridlines to the plot.
Improves readability of values.
What is the main use of plt.errorbar()?
Adds error bars to a plot.
Helps show variability or uncertainty.
What function is used to create an animated plot in Matplotlib?
FuncAnimation
Part of the matplotlib.animation module.
How do you improve performance for large datasets in Seaborn?
Use **sampling **or reduce marker sizes.
Plotting large datasets can slow performance.
What does sns.set_style(“whitegrid”) do?
Changes background style.
“darkgrid”, “white”, and “ticks” are other options.
What are the benefits of interactive visualizations?
Allows users to explore data dynamically.
Used in dashboards and web applications.
What is the primary use of dash in Python?
Creating interactive web-based visualizations.
Built on Plotly.
How can you create a dynamic visualization in Jupyter Notebook?
Use %matplotlib notebook or plotly.
Enables interactive elements.
How do you make a visualization publication-ready?
Adjust font sizes, remove unnecessary elements, use appropriate colors.
Helps in professional presentations.
True or False:
Good data visualization should prioritize aesthetics over accuracy.
FALSE
Accuracy is always more important than design.