Unit Test - Class - XII
Subject - Informatics Practices (IP - 065)
MM: 20
============================
1. Pyplot
is an interface of Python’s _________ library.
- Seaborn
- Plotly
- Ggplot
- Matplotlib
2. Which of the
following is not a valid chart type?
- Histogram
- Statistical
- Pie
- Bar
3. The command used to
give a heading to a graph is ________
- plt.show()
- plt.plot()
- plt.xlabel()
- plt.title()
4. Which function
would you use to set the limits for x-axis of the plot?
- limits()
- xlimits()
- xlim()
- lim()
5. Which function is
used to show legends?
- display()
- show()
- legend()
- legends()
6. Write a program to plot a line chart to depict the changing weekly onion prices for four weeks. Give appropriate axes labels.
Solution:
import matplotlib.pyplot as plt
week = [1,2,3,4]
prices = [40, 80, 100, 50]
plt.plot(week, prices)
plt.xlabel('week')
plt.ylabel('Onion prices')
plt.show()
7. Create an array, A, in the range 1 to 20 with values 1.25
apart. Another array B, contains the log values of the elements in the array A.
Write a program to create a scatter plot of first vs. second array (array A vs. B) with red circle marker ; specify the x-axis (containing first array’s values) title as ‘Random Values’ and y-axis title as ‘Logarithm Values’.
Solution:
import matplotlib.pyplot as plt
import numpy as np
a = np.arange(1, 20, 1.25)
b = np.log(a)
plt.plot(a, b, 'ro')
plt.xlabel('random Values')
plt.ylabel('Logarithm values')
plt.show()
8. Write a program to plot a bar chart from the medals won by India. make sure that Gold, Silver, Bronze and Total tally is represented through different colours.
Solution:
import matplotlib.pyplot as plt
info = ['Gold', 'Silver', 'Bronze', 'Total']
India = [30, 20, 20, 70]
plt.bar(info, India, color =['gold', 'silver', 'brown',
'black'])
plt.xlabel("Medal Type")
plt.ylabel('Medal Count')
plt.show()
9. Prof. Awasthi is doing some research in the field of
Environment. For some plotting purpose, he has generated some data as:
x = mu + sigma *
numpy.random.randn(10000)
Write a program to plot this data on a horizontal histogram with this data.
Solution:
import matplotlib.pyplot as plt
import numpy as np
mu = 100
sigma = 15
x = mu+sigma*np.random.randn(10000)
plt.hist(x, bins = 30, orientation = 'horizontal')
plt.title('Research data Histogram')
plt.show()
==============================
MCQ Answer: 1. Matplotlib, 2. Statistical 3. plt.title( )
4. xlim( ) 5. legend( )
===============================
No comments:
Post a Comment
Please do not any spam in the comment box.