Sent Successfully.
Home / Blog / Interview Questions / Python Libraries Interview Questions & Answers
Python Libraries Interview Questions & Answers
Table of Content
 What is function name to create legends using Matplotlib package in python?
 Is Matplotlib package have a display image function? If yes what is that function?
 Pick out the library used for plotting maps or geographical data?
 How can you create multiple subplots in one figure using Matplotlib package in Python?
 What is the function name used for variance test in Hypothesis testing in in Scipy package Python programming language?
 ________ is a declarative library for data visualization.
 What is the function name to draw the streamlines using Matplotlib package in Python?
 What is the function name to get logarithmic plots?
 Which of the following is a categorical distribution plot ?
 Plotly helps to visulaize the plots with the public without revealing your code
 Scatterplots that have histograms are called as
 Is it possible to embed bokeh plots in Django and flask apps.
 How to change the legend font size of FacetGrid plot in Seaborn?
 ___________________uses simple visualisation grammar for plotting charts
 ____________________can be used to identify proportions of the different components in a given whole.
 Which plot is used for visually assessing a statistic uncertainity?
 Primary purpose of histogram is
 Is bootstrap plot gives an estimation of the required information from the population.
 import matplotlib.pyplot as plt ;import numpy as np; x = ["APPLES", "BANANAS"];y = [400, 350] ; plt.bar(x,y); plt.show()
 If we pass categorical data then it will automatically compute the frequency of that data, The plot is
 Scatter plot based on the category is ___________
 Plotly.js is a charting library that comes with over 40 chart types, 3D charts, statistical graphs, and SVG maps.
 seaborn.factorplot() method is used to draw a categorical plot onto a FacetGrid.
 The syntax for histogram in Python is
 Pick the procedure to create a dataframe from lists?
 To initialize numpy arrays with only zeros?

What is function name to create legends using Matplotlib package in python?
 a) Legends()
 b) Legendlines()
 c) lg()
 d) legend()
Answer  d) legend()
The legends function will be used for automatic generate of figure legends.matplotlib.pyplot.legend([“blue”, “green”], bbox_to_anchor=(0.75, 1.15), ncol=2). It is an area whicg describes the elements of the graph.In the matplotlib library, we have a function called legend() which helps us to Place a legend on the axes.The Following are some more attributes of function legend() :
shadow: [None or bool] Whether to draw a shadow behind the legThe legends function will be used for the automatic generation of figure legends.matplotlib.pyplot.legend([“blue”, “green”], bbox_to_anchor=(0.75, 1.15), ncol=2). It is an area that describes the elements of the graph. In the matplotlib library, we have a function called legend() which helps us to Place a legend on the axes. The Following are some more attributes of function legend() : shadow: [None or bool] Whether to draw a shadow behind the legend. Default =None. marker scale: [None or int or float] The relative size of legend markers compared with the originally drawn ones. Default =None. num points: [None or int] The number of marker points in the legend when creating a legend entry for a Line2D (line). Default = None. fontsize: The font size of the legend. If the value is numeric the size will be the absolute font size in points. face color: [None or color] The legend’s background color. edge color: [None or color] The legend’s background patch edge color.end. Default =None.
markerscale: [None or int or float] The relative size of legend markers compared with the originally drawn ones. Default =None. numpoints: [None or int] The number of marker points in the legend when creating a legend entry for a Line2D (line). Default = None.
fontsize: The font size of the legend.If the value is numeric the size will be the absolute font size in points.
facecolor: [None or color] The legend’s background color.
edgecolor: [None or color] The legend’s background patch edge color. 
Is Matplotlib package have a display image function? If yes what is that function?
 a) viewimage()
 b) dirimage()
 c) image()
 d) imshow()
Answer  d) imshow()
yes, using matplotlib we can display the images in python using imshow() function. The imshow() function in pyplot module of matplotlib library is used to display data as an image; i.e. on a 2D format.syntax:matplotlib.pyplot.imshow(X, cmap=None, norm=None, *, aspect=None, interpolation=None, alpha=None, vmin=None, vmax=None, origin=None, extent=None, interpolation_stage=None, filternorm=True, filterrad=4.0, resample=None, url=None, data=None, **kwargs).wordcloud_ip = WordCloud(
background_color='White',
width=1800,
height=1400
).generate(ip_rev_string)
plt.imshow(wordcloud_ip) . To build a word cloud from bunch of words we can pass the height and width , give a different background do the changes accordingly to generate a cloud of words. 
Pick out the library used for plotting maps or geographical data?
 a) ggplot
 b) matplotlib
 c) geoplotlib
 d) plotly
Answer  c) geoplotlib
Geoplotlib is a toolbox for creating maps and plotting geographical data. You can use it to create a variety of map types, like choropleths, heatmaps, and dotdensity maps. We can plot 2D histograms and area maps as well. Some of the modules are the Geoplotlib module geoplotlib.layers module geoplotlib.utils module geoplotlib.core module geoplotlib.colors module. It is built on 3 key factors:1)It is very simple 2)Integration 3)performance. It also performs map rendering. The prerequisites to use this are NumPy and SciPY packages for numerical calculations and pyglet packages for graphical rendering.

How can you create multiple subplots in one figure using Matplotlib package in Python?
 a) Duelplot()
 b) Subplot()
 c) Plot()
 d) None
Answer  b) Subplot()
import numpy as np
import matplotlib.pyplot as plt
x1 = np.linspace(0.0, 5.0)
x2 = np.linspace(0.0, 2.0)
y1 = np.cos(2 * np.pi * x1) * np.exp(x1)
y2 = np.cos(2 * np.pi * x2)
plt.subplot(2, 1, 1)
plt.plot(x1, y1, 'o')
plt.title('A tale of 2 subplots')
plt.ylabel('Damped oscillation')
plt.subplot(2, 1, 2)
plt.plot(x2, y2, '.')
plt.xlabel('time (s)')
plt.ylabel('Undamped')
plt.show()
""Multiple axes can be created using subplot() function in Matplotlib package. 
What is the function name used for variance test in Hypothesis testing in in Scipy package Python programming language?
 a) stats.levene()
 b) var.test()
 c) stats.var.test()
 d) None
Answer  a) stats.levene()
stats.levene() is the function name to perform variance test in Python where it will check the data has the variation in the data or not but give through p value, if p value is less than 0.05 the data is not having equal variance and p value is greater than 0.05 then the data is having equal variance when H0 is consider as data is normal and H1 considered as data is not normal.
syntax:scipy.stats.levene(*args, center='median', proportiontocut=0.05)[source]
Perform Levene test for equal variances.
eg:from scipy.stats import levene
x = [8.88, 9.12, 9.04, 8.98, 9.00, 9.08, 9.01, 8.85, 9.07, 8.99]
y = [8.88, 8.95, 9.28, 9.44, 9.15, 9.58, 8.36, 9.18, 8.67, 9.05]
z = [8.95, 9.12, 8.95, 8.84, 9.03, 8.84, 9.06, 8.98, 8.87, 8.98]
stat, p = levene(x, y, z)
p
output:0.002431505967249681
Interpretation: With small pvalue we conclude that the populations do not have equal variances. 
________ is a declarative library for data visualization.
 a) Bokeh
 b) Gleam
 c) Altair
 d) missingno
Answer  c) Altair
Altair uses a declarative style in creating plots, it becomes very easy and quick to repeat through visualizations and experiments at a fast pace when using this library. Here declarative means while plotting any chart, we declare connection between columns to the encoding channels, such as xaxis, yaxis, etc., and the rest related to plot details are handled automatically. we can do aggregation and filtering and dynamic filtering are the cool feature of python Altair. It gives a heat map that uses a text mark attribute. The code framework remains the same but changes in mark attribute can produce different plots. It supports line charts, stacked barplot.

What is the function name to draw the streamlines using Matplotlib package in Python?
 a) Streamlines()
 b) Strlines()
 c) Streamplot()
 d) Lines()
Answer  c) Streamplot()
The streamplot function is used to draw streamlines for vector fields, you will also have control of colour and width of the line. It helps the physicists to plot fluid flow and 2D field ingradients.
Syntax: ax.streamplot(X, Y, u,v density=spacing)
# Import libraries
import numpy as np
import matplotlib.pyplot as plt
# Creating dataset
x = np.arange(0, 5)
y = np.arange(0, 5)
# Creating grids
X, Y = np.meshgrid(x, y)
# xcomponent to the right
u = np.ones((5,5))
# ycomponent zero
v = np.zeros((5, 5))
fig = plt.figure(figsize = (12, 7))
# Plotting stream plot
plt.streamplot(X, Y, u, v, density = 0.5)
# show plot
plt.show()
X and Y are 1D arrays on an evenly spaced grid,u and v are 2D arrays of velocities of x and y,density is a float value which controls the closeness of the stream lines. 
What is the function name to get logarithmic plots?
 a) semilogx()
 b) semilogy()
 c) loglog()
 d) All the above
Answer  d) All the above
All the three functions will be used to create logarithmic plots like semiology, semilogx, loglog base 2 on x, and error bar negative.
import matplotlib.pyplot as plt
# defining the values
# at X and Y axis
x = [1, 4, 5, 8, 5, 7]
y = [300, 400, 300, 400, 500, 800]
# plotting the given graph
plt.semilogx(x, y, marker = ""."",
markersize = 15,
color = ""green"")
# plot with grid
plt.grid(True)
# show the plot
plt.show() 
Which of the following is a categorical distribution plot ?
 a) boxplot()
 b) violinplot()
 c) boxenplot()
 d) All the above
Answer  d) All the above
We have different kinds of categorical distribution plots, box plots, and violin plots. These kinds of plots allow us to choose a numerical variable, like weight, and plot the distribution of weight for each category in a selected categorical variable. It is a function available in the seaborn package. We can use cat plot to combine boxplot and facet grid.syntax:sns.catplot(x="category", y="continuous", hue="smoker", kind="box", data=df)

Plotly helps to visulaize the plots with the public without revealing your code
 a) True
 b) False
 c) Can't say
 d) May be
Answer  a) True
We can embed our graphs using this library.plotly. plot() create public graphs . This is free. With a subscription, you can easily make charts private or secret via the sharing argument. The plots are generated using GUI. This helps in webbased data visualizations. we can make 3D graph,density heatmap,tree map etc. import plotly.express as px fig = px.imshow([[1, 20, 30], [20, 1, 60], [30, 60, 1]]) fig.show()

Scatterplots that have histograms are called as
 a) Marginal Plots
 b) Subplots
 c) Treeplots
 d) All the above
Answer  a) Marginal Plots
Marginal plots are used to find the relationship between x and y and x and x and observe their distributions. Such scatter plots that have histograms, box plots, or dot plots in the margins of respective x and y axes. Seaborn gives the marginal plots with seaborn sns.joint plot(x=df["sepal_length"], y=df["sepal_width"], kind='scatter') Using Plotly also these plots are also done.

Is it possible to embed bokeh plots in Django and flask apps.
 a) Yes
 b) No
 c) May Be
 d) May not be
Answer  a) Yes
We can embed bokeh documents into web pages.These applications require a Bokeh server to work. Having a Bokeh server helps us in connecting events and tools to realtime Python callbacks that execute on the server.Bokeh. json, bokeh html , bokeh serve helps in rendering.bokeh.models which is a low level interface that provides high flexibility to application developers. from bokeh.plotting import figure, output_notebook, show # output to notebook output_notebook() # create figure p = figure(plot_width = 400, plot_height = 400) # add a line renderer p.line([1, 2, 3, 4, 5], [3, 1, 2, 6, 5], line_width = 2, color = "green") # show the results show(p).

How to change the legend font size of FacetGrid plot in Seaborn?
 a) sns.displot with FacetGrid.legend
 b) sns.distplot with facet.legend
 c) sns.distplot with facetfont.legend
 d) All the above
Answer  a) sns.displot with FacetGrid.legend
We can access the legend from the FacetGrid in which sns.displot will return with FacetGrid.legend.
import seaborn as sns
testData = sns.load_dataset(""testexample"")
gplot = sns.displot(data=testData, x=""total_amt"", hue=""day"")
# Legend title
gplot.legend.get_title().set_fontsize(20)
# Legend texts
for text in gplot.legend.texts:
text.set_fontsize(20) 
___________________uses simple visualisation grammar for plotting charts
 a) Atlair
 b) Bokeh
 c) matplotlib
 d) None of these
Answer  a) Atlair
Altair's API is easy to understand. Unlike Matplotlib, it's declarative: you only need to specify the links between the data columns to the encoding channels, and the rest of the plotting is handled automatically. This sounds abstract but is a big deal when you are working with data, and it makes visualizing information fast and intuitive. syntax:import seaborn as sns import Altair as alt titanic = sns.load_dataset("titanic") alt.Chart(titanic).mark_bar().encode( x='class', y='count()' )

____________________can be used to identify proportions of the different components in a given whole.
 a) Pie
 b) Area
 c) both
 d) None
Answer  a) Pie
Pie charts can be used to identify proportions of the different components in a given whole.

Which plot is used for visually assessing a statistic uncertainity?
 a) Lag
 b) RadViz
 c) Bootstrap
 d) All the above
Answer  c) Bootstrap
Bootstrap plot is the result for the combination of resulting plots and histograms.

Primary purpose of histogram is
 a) spread of data
 b) outlier detection
 c) both
 d) All the above
Answer  a) spread of data
The histogram helps in observing the spread of data and the secondary purpose of the plot is outlier detection. This is available in matplotlib package.import matplotlib .pyplot as plt plt.hist()

Is bootstrap plot gives an estimation of the required information from the population.
 a) True
 b) False
Answer  a) True
We can calculate the uncertainty of a statistic of a population mathematically, using confidence intervals. The bootstrap plot gives an estimation of the required information from the population, not the exact values.

import matplotlib.pyplot as plt ;import numpy as np; x = ["APPLES", "BANANAS"];y = [400, 350] ; plt.bar(x,y); plt.show()
 a) The code has syntax error
 b) The code has Value error
 c) The code has Name error
 d) No error
Answer  d) No error
The code has no error. The code is written is for barplot. the barplot holds good for categorical data .matplotlib package is best for basic visualization. This is a univariate plot where we have the variables on the Xaxis and y being data.

If we pass categorical data then it will automatically compute the frequency of that data, The plot is
 a) Histogram
 b) Scatter plot
 c) only A
 d) None
Answer  a) Histogram
The primary purpose of Histogram gives the

Scatter plot based on the category is ___________
 a) Stripplot
 b) Violinplot
 c) Countplot
 d) All the above
Answer  a) Stripplot
It is a complement to boxplot and violin plot .It is used to draw scatterplot for categorical.Syntax: seaborn.stripplot(*, x=None, y=None, hue=None, data=None, order=None, hue_order=None, jitter=True, dodge=False, orient=None, color=None, palette=None, size=5, edgecolor=’gray’, linewidth=0, ax=None, **kwargs)

Plotly.js is a charting library that comes with over 40 chart types, 3D charts, statistical graphs, and SVG maps.
 a) True
 b) False
Answer  a) True
Plotly graph objects are a highlevel interface to plotly which are easy to use. It can plot various types of graphs and charts like scatter plots, line charts, bar charts, box plots, histograms, pie charts, etc.

seaborn.factorplot() method is used to draw a categorical plot onto a FacetGrid.
 a) True
 b) False
Answer  a) True
FacetGrid class helps in visualizing the distribution of one variable as well as the relationship between multiple variables separately within subsets of your dataset using multiple panels.

The syntax for histogram in Python is
 a) plt.hist(x, bins = number of bins)
 b) plt.show()
 c) both
 d) none
Answer  a) plt.hist(x, bins = number of bins)
The histogram plot is observed by using a package called matplotlib. plt.hist(). SVG histogram, animated histogram,2D histogram with rectangular bins. The histogram by default calculates bins using math calculations. The other way round we can specify bins of your choice.

Pick the procedure to create a dataframe from lists?
 a) An empty dataframe is created
 b) Add lists as individuals columns to the list
 c) 1 follows 2
 d) 2 follows 1
Answer  c) 1 follows 2
To create a dataframe from lists ,1)create an empty dataframe2)add lists as individuals columns to the list. df=pd.DataFrame() bikes=["bajaj","tvs","herohonda","kawasaki","bmw"]
cars=["lamborghini","masserati","ferrari","hyundai","ford"] df["cars"]=cars df["bikes"]=bikes df. Dataframe canbe done using list with index and column names,Using zip() for zipping two lists,Creating DataFrame using multidimensional list,Using lists in dictionary to create dataframe. Calling DataFrame constructor after zipping both lists, with columns specified df = pd.DataFrame(list(zip(lst, lst2)), columns =['Name', 'val']) 
To initialize numpy arrays with only zeros?
 a) numpy.zeros(shape, dtype=float, order='C')
 b) a = np.zeros(8)
 c) a = np.zeros((3, 4))
 d) All the Above
Answer  d) All the Above
To create zeros with numpy array is:numpy.zeros(shape, dtype=float, order='C') shape= any integer value .To create a twodimensional array of zeros, pass the shape i.e., number of rows and columns as the value to shape parameter.we can create numpy zeros array with specific datatype, pass the required datatype as dtype parameter.np.zeros((2, 1))
import numpy as np
array_mix_type = np.zeros((2, 2), dtype=[('x', 'int'), ('y', 'float')])
print(array_mix_type)
print(array_mix_type.dtype) to get the output with desired data type
Navigate to Address
360DigiTMG  Data Analytics, Data Science Course Training Hyderabad
256/2/19, 3rd floor, Vijaya Towers, near Meridian School, Ayyappa Society Rd, Madhapur, Hyderabad, Telangana 500081
099899 94319