Playing as a guest? to earn XP and track your progress.
๐ Plotting with PyPlot Quiz
๐ Plotting with PyPlot
What is the primary purpose of Data Visualization?
To compress data files
To translate information into a visual context for easier understanding
To encrypt data for security
To delete outliers from a dataset
Data Visualization translates information into a visual context like a map or graph to make data easier for the human brain to understand and pull insights from.
Which Python library serves as the foundation for many visualization libraries and provides 2D plotting capabilities?
NumPy
Pandas
Matplotlib
SciPy
Matplotlib is a comprehensive library for creating static, animated, and interactive visualizations in Python and serves as the foundation for others.
Which module within Matplotlib provides a state-machine interface mimicking MATLAB?
pylab
pyplot
seaborn
tkinter
Pyplot is the specific module that provides a state-machine interface to the underlying plotting library, mimicking MATLAB.
In Matplotlib architecture, what is considered the top-level container for all plot elements?
Axis
Axes
Figure
Legend
The Figure is the top-level container, acting as the canvas or window where the graph and its components are drawn.
What is the region of the figure where the data is actually plotted?
Axes
Title
Grid
Tick
The Axes is the region of the figure where data is plotted. It contains the X-axis and Y-axis.
What is the function of the 'Axis' object in a plot?
It holds the title
It represents the whole window
It handles the scale, limits, and generates ticks
It connects data points with lines
The Axis objects are number-line-like objects that handle the scale and limits of the graph, generating ticks and tick labels.
Which element identifies what different colors or line styles represent in a plotted data series?
Marker
Label
Legend
Title
A Legend is an area describing the elements of the graph, identifying what different colors or line styles represent.
What chart type is best used to show the frequency distribution of continuous data?
Bar Chart
Pie Chart
Histogram
Scatter Plot
A Histogram is a graphical representation of the frequency distribution of a set of continuous data using bins.
Which of the following displays data based on a five-number summary including quartiles?
Frequency Polygon
Box Plot
Scatter Plot
Area Chart
A Box Plot is a standardized way of displaying data distribution based on the minimum, Q1, median, Q3, and maximum.
Which layer of Matplotlib handles the rendering of the plot to a file or screen?
Artist Layer
Scripting Layer
Backend Layer
Frontend Layer
The Backend Layer handles the rendering of the plot to a file or screen (e.g., PNG, PDF).
What is the standard convention for importing the pyplot module?
import matplotlib.pyplot as py
import matplotlib.pyplot as plt
import pyplot as pl
import matplotlib as plt
Standard convention dictates using the alias plt (or sometimes pl) for matplotlib.pyplot.
Which function is used to create a standard line chart?
plt.line()
plt.create_line()
plt.plot()
plt.draw()
plt.plot() is the function used for creating line charts.
If you run plt.plot([10, 20, 30]), what will be the X-axis values?
[10, 20, 30]
[1, 2, 3]
[0, 1, 2]
[0, 10, 20]
If only one list is provided, Matplotlib assumes they are Y-values and automatically generates X-values starting from 0 ([0, 1, 2]).
Which function is used to display the final graph to the user?
plt.render()
plt.display()
plt.show()
plt.output()
plt.show() is used to display the final graph.
How do you set the size of a figure in Matplotlib?
plt.size(10, 5)
plt.figure(figsize=(10, 5))
plt.set_size(10, 5)
plt.plot(size=(10, 5))
The size of the figure is controlled using plt.figure(figsize=(width, height)).
Which function turns on the grid lines for a plot?
plt.grid(True)
plt.lines(True)
plt.show_grid()
plt.axis('grid')
plt.grid(True) turns on the grid lines for both axes.
In plt.plot(), which argument changes the line thickness?
thick
width
linewidth
size
The linewidth (or lw) argument changes the thickness of the line.
Which argument is used to specify the line style as dashed?
style='dashed'
linestyle='--'
type='dash'
line='--'
The linestyle (or ls) argument controls the style. '--' or 'dashed' represents a dashed line.
What does the 'marker' argument do in a plot command?
Changes the background color
Adds a symbol at each data point
Adds a legend
Changes the axis ticks
The marker argument adds a symbol (like a dot or star) to represent a specific data point.
Which function is primarily used to observe correlations between two variables without connecting lines?
plt.plot()
plt.bar()
plt.scatter()
plt.hist()
A scatter plot (plt.scatter()) displays data points without connecting lines and is used to observe relationships or correlations.
Which function creates a vertical bar chart?
plt.bar()
plt.barv()
plt.column()
plt.hist()
plt.bar() creates a vertical bar chart.
Which function creates a horizontal bar chart?
plt.bar(orientation='horizontal')
plt.hbar()
plt.barh()
plt.horizontal()
plt.barh() is used to create a horizontal bar chart.
What must be done to plot multiple bar charts side-by-side?
Use the 'stack' argument
Manually offset the X-coordinates of the bars
Call plt.show() twice
It is not possible in Matplotlib
To plot multiple data series in bar charts, the X-coordinates of the bars must be offset manually so they do not overlap.
In a pie chart, which parameter is used to display the percentage value on the slices?
show_pct
percentage
autopct
label
The autopct parameter is used to display the percentage value on the slices.
Which pie chart parameter allows separating a slice from the main pie?
detach
explode
separate
slice
The explode parameter allows separating a slice from the main pie to highlight it.
Which function sets the title of the chart?
plt.header()
plt.name()
plt.label()
plt.title()
plt.title() sets the chart title.
How do you set the label for the X-axis?
plt.xaxis()
plt.xlabel()
plt.labelx()
plt.xtitle()
plt.xlabel() sets the label for the X-axis.
To display a legend, what argument must be included in the plot function?
legend=True
name='text'
label='text'
id='text'
plt.legend() requires label arguments in the plot function to identify the series.
Which function saves the current figure to a file?
plt.save()
plt.download()
plt.export()
plt.savefig()
plt.savefig() is used to save the graph to a storage device.
Why should plt.savefig() be called before plt.show()?
It is a syntax error otherwise
Because plt.show() clears the plot from memory
The file format requires it
It doesn't matter
Always call plt.savefig() before plt.show() because show() resets the canvas/flushes the buffer, resulting in a blank saved image if called after.
Which argument defines the number of intervals in a histogram?
intervals
bins
range
groups
The bins argument defines the number of intervals or ranges in a histogram.
What is the key visual difference between a Bar Chart and a Histogram?
Histograms have gaps between bars
Bar charts show continuous data
Histograms usually have no gaps between bars
Bar charts cannot be colored
Histograms show continuous data distribution and usually have no gaps between bars, whereas Bar charts show discrete categories and usually have gaps.
A Frequency Polygon is similar to a histogram but uses what to connect midpoints?
Bars
Lines
Dots
Circles
A frequency polygon uses lines to join the midpoints of each interval (bin) at their respective heights.
In a Box Plot, what does the box itself represent?
The full range of data
The outliers
The Interquartile Range (IQR)
The median only
The box in a box plot represents the Interquartile Range (IQR), from Q1 to Q3.
Which method allows you to plot directly from a Pandas DataFrame?
df.chart()
df.plot()
pd.plot(df)
df.create_plot()
The built-in wrapper df.plot() allows plotting directly from a Pandas DataFrame.
What color does the code 'k' represent in Matplotlib?
Blue
Black
Green
Cyan
The color code 'k' represents Black.
What color does the code 'w' represent in Matplotlib?
White
Watermelon
Wheat
Wine
The color code 'w' represents White.
Which marker code represents a square?
'sq'
's'
'q'
'box'
The marker code 's' represents a Square.
Which marker code represents a circle?
'c'
'o'
'cir'
'.'
The marker code 'o' is used for a Circle.
What is the default line style in Matplotlib?
Dashed
Dotted
Solid
None
The default line style is 'solid' or '-'.
Which kind argument would you use in df.plot() to create a scatter plot?
'scatter'
'point'
'dot'
's'
You use kind='scatter' in df.plot() to create a scatter plot.
What happens if you try to pass linestyle to plt.scatter()?
It changes the border style of the dots
It connects the dots with lines
It is ignored or invalid
It crashes Python
Scatter plots do not have connecting lines, so linestyle is invalid or ignored.
What error occurs if the lists passed to plt.plot(x, y) have different lengths?
SyntaxError
ValueError
TypeError
IndexError
Matplotlib raises a ValueError (x and y must have same first dimension) if the lists have different lengths.
Which command manually sets the limits of the Y-axis?
plt.ylim()
plt.yticks()
plt.ylimit()
plt.axis_y()
plt.ylim() is used to manually set the range/limits of the Y-axis.
Which plot type implies data continuity?
Scatter Plot
Line Chart
Bar Chart
Pie Chart
A line chart connects data points, implying continuity between them.
What does the width parameter control in plt.bar()?
Height of the bars
Thickness of the bars
Space between bars
Axis width
The width parameter controls the thickness of the bars.
Which plot helps specifically in identifying outliers?
Pie Chart
Box Plot
Area Chart
Donut Chart
Box plots explicitly display outliers as individual points outside the whiskers.
What is the correct syntax to install Matplotlib via command line?
install matplotlib
pip install matplotlib
python install matplotlib
pip download matplotlib
The standard command is pip install matplotlib.
In a histogram, if bins is a sequence (list), what does it define?
The number of bins
The specific edges of the bins
The height of the bins
The color of the bins
If bins is a sequence, it defines the specific bin edges.
What is the alias for triangle up marker?
't'
'^'
'v'
'>'
The marker code '^' represents a Triangle Up.