Data Visualization & Storytelling in Python Flashcards

This covers various data visualization in Python

1
Q

What Python libraries are commonly used for data visualization?

A
  • Matplotlib
  • Seaborn
  • Plotly
  • ggplot
  • Altair

Each library has strengths depending on the use case.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is Matplotlib?

A

A low-level visualization library for creating static, animated, and interactive plots.

It provides full control over plot appearance.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is Seaborn built on?

A

Matplotlib

Seaborn simplifies statistical visualizations.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What command in Matplotlib is used to create a basic line plot?

A

plt.plot()

Part of Matplotlib’s pyplot module.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Fill in the blank:

plt.show() is used to ____ in Matplotlib.

A

Display the figure.

Without plt.show(), plots may not render properly in some environments.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How do you import Seaborn?

A

import seaborn as sns

The alias sns is commonly used.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How do you load a built-in Seaborn dataset?

A

sns.load_dataset(“dataset_name”)

Example: sns.load_dataset(“iris”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is the default style of Seaborn?

A

darkgrid

Seaborn styles improve readability.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What function is used to create a histogram in Seaborn?

A

sns.histplot()

Histograms help visualize distributions.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How do you change the figure size in Matplotlib?

A

plt.figure(figsize=(width, height))

Helps with readability.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Which function is used to create a scatter plot in Matplotlib?

A

plt.scatter(x, y)

Scatter plots show relationships between two numerical variables.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is the difference between sns.histplot() and sns.kdeplot()?

A

histplot() shows bar-like frequency, while kdeplot() smooths it into a curve.

KDE plots estimate probability distributions.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How do you create a box plot in Seaborn?

A

sns.boxplot(x=”column”, data=df)

Box plots show distributions and outliers.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What does a violin plot add compared to a box plot?

A

It shows kernel density estimation (KDE) along with quartiles.

sns.violinplot() is used for this.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What function is used to create a bar chart in Seaborn?

A

sns.barplot(x=”category”, y=”value”, data=df)

Used for categorical comparisons.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is the main advantage of using Plotly over Matplotlib?

A

Plotly supports interactivity.

Good for dashboards and dynamic exploration.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

Which function in Plotly is used for line plots?

A

px.line(df, x=”column_x”, y=”column_y”)

px is short for plotly.express.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

What is the main difference between sns.barplot() and sns.countplot()?

A

barplot()requires numerical y-values, while countplot() works with categorical counts.

Count plots count occurrences automatically.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

What is the purpose of ax.set_title(“Title”) in Matplotlib?

A

Adds a title to the plot.

Helps provide context.

20
Q

How do you change the color palette in Seaborn?

A

sns.set_palette(“color_palette”)

Example: “pastel”, “muted”, “deep”.

21
Q

What argument in Seaborn adjusts transparency?

A

alpha

Example: sns.scatterplot(x, y, alpha=0.5).

22
Q

What does plt.savefig(“plot.png”) do?

A

Saves the plot as an image file.

Supports formats like PNG, JPG, SVG.

23
Q

How do you add labels to the x-axis and y-axis in Matplotlib?

A

plt.xlabel(“X Label”), plt.ylabel(“Y Label”)

Labels are crucial for clarity.

24
Q

What is the advantage of using tight_layout()?

A

Adjusts spacing automatically.

Prevents overlapping labels.

25
Q

What does plt.legend() do?

A

Adds a legend to the plot.

Legends help differentiate categories.

26
Q

How do you create a correlation heatmap in Seaborn?

A

sns.heatmap(df.corr(), annot=True, cmap=”coolwarm”)

Heatmaps visualize correlations between variables.

27
Q

What does hue do in Seaborn plots?

A

Adds color differentiation based on a categorical variable.

Example: sns.scatterplot(x, y, hue=”category”, data=df).

28
Q

What function is used for facet grids in Seaborn?

A

sns.FacetGrid()

Creates multiple subplots for different categories.

29
Q

What is the best visualization for time series data?

A

Line plot

sns.lineplot() is commonly used.

30
Q

What are “small multiples” in data visualization?

A

Repeating the same chart for different subsets of data.

Helps in comparative analysis.

31
Q

How do you rotate x-axis labels in Matplotlib?

A

plt.xticks(rotation=45)

Useful when dealing with long category names.

32
Q

What does plt.subplots() do?

A

Creates multiple plots in a single figure.

Used for dashboards or comparisons.

33
Q

How do you customize tick labels in Matplotlib?

A

plt.xticks(ticks, labels)

Helps improve readability.

34
Q

What does sns.pairplot(df) do?

A

Plots pairwise relationships in the dataset.

Great for EDA and correlation analysis.

35
Q

What is a bubble chart?

A

A scatter plot where point size represents a third variable.

Used in business analytics.

36
Q

What does plt.grid(True) do?

A

Adds gridlines to the plot.

Improves readability of values.

37
Q

What is the main use of plt.errorbar()?

A

Adds error bars to a plot.

Helps show variability or uncertainty.

38
Q

What function is used to create an animated plot in Matplotlib?

A

FuncAnimation

Part of the matplotlib.animation module.

39
Q

How do you improve performance for large datasets in Seaborn?

A

Use **sampling **or reduce marker sizes.

Plotting large datasets can slow performance.

40
Q

What does sns.set_style(“whitegrid”) do?

A

Changes background style.

“darkgrid”, “white”, and “ticks” are other options.

41
Q

What are the benefits of interactive visualizations?

A

Allows users to explore data dynamically.

Used in dashboards and web applications.

42
Q

What is the primary use of dash in Python?

A

Creating interactive web-based visualizations.

Built on Plotly.

43
Q

How can you create a dynamic visualization in Jupyter Notebook?

A

Use %matplotlib notebook or plotly.

Enables interactive elements.

44
Q

How do you make a visualization publication-ready?

A

Adjust font sizes, remove unnecessary elements, use appropriate colors.

Helps in professional presentations.

45
Q

True or False:

Good data visualization should prioritize aesthetics over accuracy.

A

FALSE

Accuracy is always more important than design.