Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Programming Articles - Page 1320 of 3366
15K+ Views
To plot a histogram using Matplotlib, we can follow the steps given below −Make a list of numbers and assign it to a variable x.Use the plt.hist() method to plot a histogram.Compute and draw the histogram of *x*.We can pass n-Dimensional arrays in the hist argument also.To show the plotted figure, use the plt.show() method.Examplefrom matplotlib import pyplot as plt x = [300, 400, 500, 2000, 10] plt.hist(x, 10) plt.show()Output
5K+ Views
To display multiple images in one figure, we can follow the steps given below −Initialize the number of rows and cols. nrows*ncols subplot will be created in the current figure. nrows = 2 and ncols = 2, i.e., 2*2 = 4 subplots can be created.Now add the figures at different indices from 1 to 4.Use plt.subplot(2, 2, 1) to add new images, i.e., pie at index 1.To plot a pie chart, pass a list of numbers. Pie charts will be split into the size of list and %age section will depend upon the values in the list.Set the title of ... Read More
1K+ Views
To pick a new color for each plotted line within a figure, use the following steps −Setup X-axis and Y-axis labels for the diagram.Set the current .rc parameters. For axes facecolor, the group is axes.Use a cycler to set the color for the group of lines. The color list consists of ‘r’ for red, ‘g’ for green, ‘b’ for blue, and ‘y’ for yellow.Cycler class helps to create a new Cycler object from a single positional argument, a pair of positional arguments, or the combination of keyword arguments.Plot the number of lines with different colors.Use plt.show() to show the figure.Exampleimport ... Read More
8K+ Views
To hide the axis value but to keep the axis tick labels, we can perform the following steps −Plot a line using the plot( ) method.Set X and Y labels using x label and y label methods.Using plt.gca(), get the current axis, creating one if necessary.Use xaxis.set_ticklabels() with an empty list.Use yaxis.set_ticklabels() with an empty list.To show the diagram, use the plt.show() method.Exampleimport matplotlib.pyplot as plt plt.plot([0, 5], [0, 5]) plt.ylabel("Y-axis ") plt.xlabel("X-axis ") ax = plt.gca() ax.axes.xaxis.set_ticklabels([]) ax.axes.yaxis.set_ticklabels([]) plt.show()OutputRead More
8K+ Views
To save the images in Python with very high quality, you need to follow the steps given below −Create fig and ax variables using subplots method, where default nrows and ncols are 1.Plot the lines using plot() method.We can add axes labels using ylabel() and xlabel().To get a high-quality image, we can use .eps image format.You can increase the dot per inch value, i.e., dpi.Using savefig() method, we can save the image locally.To show the figure, use plt.show().Exampleimport matplotlib.pyplot as plt fig, ax = plt.subplots() plt.plot([0, 5], [0, 5]) plt.ylabel("Y-axis ") plt.xlabel("X-axis ") image_format = 'eps' ... Read More
7K+ Views
To shift the Y-axis ticks from left to right, we can perform the following steps −Create a figure using the figure() method.Using the above figure method, create the axis of the plot, using add_subplot(xyz), where x is row, y is column, and z is index.To shift the Y-axis ticks from left to right, use ax.yaxis.tick_right() where ax is axis created using add_subplot(xyz) method.Now plot the line using plot() method, with given x and y points, where x and y points can be created using np.array() method.Set up x and y labels, e.g., X-axis and Y-axis , using xlabel and ylabel ... Read More
186 Views
In this problem, we are given an integer N. Our task is to create a program to Find Nth term of series 1, 2, 2, 4, 4, 4, 4, 8, 8, 8, 8, 8, 8, 8, 8…Let’s take an example to understand the problem, InputN = 7Output4Solution ApproachA simple approach to solve the problem is using a loop to find the term at the nth position. The terms will be updated by doubling after each iteration. And adding it to the term counter.Program to illustrate the working of our solution, Example#include using namespace std; int calcNthTerm(int N) { ... Read More
375 Views
In this problem, we are given an integer N. Our task is to create a program to Find Nth term of series 0, 2, 4, 8, 12, 18…Let’s take an example to understand the problem, InputN = 5Output12Solution ApproachA simple approach to solve the problem is the formula for the Nth term of the series. For this, we need to observe the series and then generalise the Nth term.The formula of Nth term isT(N) = ( N + (N - 1)*N ) / 2Program to illustrate the working of our solution, Example Live Demo#include using namespace std; int calcNthTerm(int N) ... Read More
447 Views
In this problem, we are given an integer N. Our task is to create a program to Find Nth term of series 1, 4, 15, 72, 420…Let’s take an example to understand the problem, InputN = 4Output72Solution ApproachA simple approach to solve the problem is the formula for the Nth term of the series. For this, we need to observe the series and then generalise the Nth term.The series can be seen as the product of factorial and a some variables, 1, 4, 15, 72, 420… 1!*(X1), 2!*(X2), 3!*(X3), 4!*(X4), 5!*(X5)... 1*(1), 2*(2), 6*(5/2), 24*(3), 120*(7/2)...Here, the series of product ... Read More
237 Views
In this problem, we are given an integer N and a recursive function that given Nth term as a function of other terms. Our task is to create a program to Find Nth term (A matrix exponentiation example).The function isT(n) = 2*( T(n-1) ) + 3*( T(n-2) ) Initial values are T(0) = 1 , T(1) = 1Let’s take an example to understand the problem, InputN = 4Output41ExplanationT(4) = 2* (T(3)) + 3*(T(2)) T(4) = 2* ( 2*(T(2)) + 3*(T(1)) ) + 3*( 2* (T(1)) + 3*(T(0)) ) T(4) = 2*( 2*(2* (T(1)) + 3*(T(0))) + 3*(1) ) + ... Read More