Question and Answers For Pyplots

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 11

Question related to PyPlots -

1. Write a Python program to draw a line with suitable label in the x axis, y axis
and a title.

2. Write a Python program to draw a line using given axis values with suitable
label in the x axis , y axis and a title.

3. Write a Python program to draw line charts of the financial data of Alphabet
Inc. between October 3, 2016 to October 7, 2016.

Sample Financial data (fdata.csv):


Date,Open,High,Low,Close
10-03-16,774.25,776.065002,769.5,772.559998
10-04-16,776.030029,778.710022,772.890015,776.429993
10-05-16,779.309998,782.070007,775.650024,776.469971
10-06-16,779,780.47998,775.539978,776.859985
10-07-16,779.659973,779.659973,770.75,775.080017

4. Write a Python program to plot two or more lines and set the line markers.
5. Write a Python program to display the current axis limits values and set new
axis values.

6. Write a Python program to plot quantities which have an x and y position.


The code snippet gives the output shown in the following screenshot:

7. Create a histogram that plots two ndarrays x and y with 48 bins, in stacked
horizontal histogram.

8. Write a Python program to plot several lines with different format styles in one
command using arrays.

9. Write a Python program to create multiple plots.


10. The plot method on Series and DataFrame is just a simple wrapper around :

a) gplt.plot()

b) plt.plot()

c) plt.plotgraph()

d) none of the Mentioned

11. Point out the correct combination with regards to kind keyword for graph plotting:
a) ‘hist’ for histogram
b) ‘box’ for boxplot
c) ‘area’ for area plots
d) all of the Mentioned
12. Which of the following value is provided by kind keyword for barplot ?
a) barh
b) kde
c) hexbin
d) none of the Mentioned

13. You can create a scatter plot matrix using the __________ method in pandas.tools.plotting.
a) sca_matrix
b) scatter_matrix
c) DataFrame.plot
d) all of the Mentioned

14. Point out the wrong combination with regards to kind keyword for graph plotting:
a) ‘scatter’ for scatter plots
b) ‘kde’ for hexagonal bin plots
c) ‘pie’ for pie plots
d) none of the Mentioned

15. Which of the following plots are used to check if a data set or time series is random ?
a) Lag
b) Random
c) Lead
d) None of the Mentioned

16. Plots may also be adorned with error bars or tables.


a) True
b) False

17. Which of the following plots are often used for checking randomness in time series ?
a) Autocausation
b) Autorank
c) Autocorrelation
d) None of the Mentioned

18__________ plots are used to visually assess the uncertainty of a statistic.


a) Lag
b) RadViz
c) Bootstrap
d) None of the Mentioned

19. Andrews curves allow one to plot multivariate data.


a) True
b) False
20. Write the syntax to import Pyplot library?

21.What is histogram?
22. What is data visualization?

23. Name some commonly used chart types?

24.Name the functions that are used to create line chart.

25. Name the functions that are used to create bar chart.

Answers related to PyPlots -


Answer 1:
import matplotlib.pyplot as plt
X =range(1,50)
Y =[value *3for value in X]
print("Values of X:")
print(*range(1,50))
print("Values of Y (thrice of X):")
print(Y)
# Plot lines and/or markers to the Axes.
plt.plot(X, Y)
# Set the x axis label of the current axis.
plt.xlabel('x - axis')
# Set the y axis label of the current axis.
plt.ylabel('y - axis')
# Set a title
plt.title('Draw a line.')
# Display the figure.
plt.show()

Answer 2:

import matplotlib.pyplot as plt


# x axis values
x =[1,2,3]
# y axis values
y =[2,4,1]
# Plot lines and/or markers to the Axes.
plt.plot(x, y)
# Set the x axis label of the current axis.
plt.xlabel('x - axis')
# Set the y axis label of the current axis.
plt.ylabel('y - axis')
# Set a title
plt.title('Sample graph!')
# Display a figure.
plt.show()

Answer 3:

import matplotlib.pyplot as plt


import pandas as pd
df = pd.read_csv('fdata.csv', sep=',', parse_dates=True, index_col=0)
df.plot()
plt.show()

Answer 4:

import matplotlib.pyplot as plt


# x axis values
x =[1,4,5,6,7]
# y axis values
y =[2,6,3,6,3]

# plotting the points


plt.plot(x, y, color='red', linestyle='dashdot', linewidth =3,
marker='o', markerfacecolor='blue', markersize=12)
#Set the y-limits of the current axes.
plt.ylim(1,8)
#Set the x-limits of the current axes.
plt.xlim(1,8)

# naming the x axis


plt.xlabel('x - axis')
# naming the y axis
plt.ylabel('y - axis')

# giving a title to my graph


plt.title('Display marker')
# function to show the plot
plt.show()

Answer 5:

import matplotlib.pyplot as plt

X =range(1,50)

Y =[value *3for value in X]

plt.plot(X, Y)

plt.xlabel('x - axis')

plt.ylabel('y - axis')

plt.title('Draw a line.')

# shows the current axis limits values

print(plt.axis())

# set new axes limits

# Limit of x axis 0 to 100

# Limit of y axis 0 to 200

plt.axis([0,100,0,200])

# Display the figure.

plt.show()

Answer 6:

import numpy as np

import pylab as pl

# Make an array of x values

x1 =[2,3,5,6,8]

# Make an array of y values for each x value

y1 =[1,5,10,18,20]

# Make an array of x values


x2 =[3,4,6,7,9]

# Make an array of y values for each x value

y2 =[2,6,11,20,22]

# set new axes limits

pl.axis([0,10,0,30])

# use pylab to plot x and y as red circles

pl.plot(x1, y1,'b*', x2, y2,'ro')

# show the plot on the screen

pl.show()

Answer 7:

import numpy as np

import matplotlib.pyplot as plt

# Sampled time at 200ms intervals

t = np.arange(0.,5.,0.2)

# green dashes, blue squares and red triangles

plt.plot(t, t,'g--', t, t**2,'bs', t, t**3,'r^')

plt.show()

Answer 8:

import numpy as np
import matplotlib.pyplot as plt

# Sampled time at 200ms intervals


t = np.arange(0.,5.,0.2)

# green dashes, blue squares and red triangles


plt.plot(t, t,'g--', t, t**2,'bs', t, t**3,'r^')
plt.show()

Answer 9:

import matplotlib.pyplot as plt


fig = plt.figure()
fig.subplots_adjust(bottom=0.020, left=0.020, top = 0.900,
right=0.800)

plt.subplot(2, 1, 1)
plt.xticks(()), plt.yticks(())

plt.subplot(2, 3, 4)
plt.xticks(())
plt.yticks(())

plt.subplot(2, 3, 5)
plt.xticks(())
plt.yticks(())

plt.subplot(2, 3, 6)
plt.xticks(())
plt.yticks(())

plt.show()

10. The plot method on Series and DataFrame is just a simple wrapper around :

a) gplt.plot()

b) plt.plot()

c) plt.plotgraph()

d) none of the Mentioned

Answer: b
Explanation: If the index consists of dates, it calls gcf().autofmt_xdate() to try to format the x-axis
nicely.

11. Point out the correct combination with regards to kind keyword for graph plotting:
a) ‘hist’ for histogram
b) ‘box’ for boxplot
c) ‘area’ for area plots
d) all of the Mentioned
Answer: d
Explanation: The kind keyword argument of plot() accepts a handful of values for plots other than the
default Line plot.

12. Which of the following value is provided by kind keyword for barplot ?
a) barh
b) kde
c) hexbin
d) none of the Mentioned

Answer: b
Explanation: You can create density plots using the Series/DataFrame.plot.

13. You can create a scatter plot matrix using the __________ method in pandas.tools.plotting.
a) sca_matrix
b) scatter_matrix
c) DataFrame.plot
d) all of the Mentioned

Answer: b
Explanation: You can create density plots using the Series/DataFrame.plot.

14. Point out the wrong combination with regards to kind keyword for graph plotting:
a) ‘scatter’ for scatter plots
b) ‘kde’ for hexagonal bin plots
c) ‘pie’ for pie plots
d) none of the Mentioned

Answer: b
Explanation: kde is used for density plots.

15. Which of the following plots are used to check if a data set or time series is random ?
a) Lag
b) Random
c) Lead
d) None of the Mentioned

Answer: a
Explanation: Random data should not exhibit any structure in the lag plot.

16. Plots may also be adorned with error bars or tables.


a) True
b) False

Answer: a
Explanation: There are several plotting functions in pandas.tools.plotting.
17. Which of the following plots are often used for checking randomness in time series ?
a) Autocausation
b) Autorank
c) Autocorrelation
d) None of the Mentioned

Answer: c
Explanation: If time series is random, such autocorrelations should be near zero for any and all time-
lag separations.

18__________ plots are used to visually assess the uncertainty of a statistic.


a) Lag
b) RadViz
c) Bootstrap
d) None of the Mentioned

Answer: c
Explanation: Resulting plots and histograms are what constitutes the bootstrap plot.

19. Andrews curves allow one to plot multivariate data.


a) True
b) False

Answer: a
Explanation: Curves belonging to samples of the same class will usually be closer together and form
larger structures

20.import matplotlib.pyplot.
21. A histogram is a statistical tool used to
summarized discrete or continuous data.
22. General term that describe any effort to help people understand significance
of data by placing it in visual context.

23. Line chart,Bar chart ,scatter chart

24.matplotlib.pyplot.plot()

25. matplotlib.pyplot.bar()

You might also like