
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
Found 10476 Articles for Python

1K+ Views
To avoid line color repetition in matplotlib.pyplot we can take the following steps −StepsSet the figure size and adjust the padding between and around the subplots.Create x and y data points using numpy.Plot the x and y data points using plot() method.In the plot() method, use a unique hexadecimal value for the color attribure, for example, color="#980ab5" to set the graph in a unique color. You can also specify a particular color of your choice, for example, color="green".To display the figure, use show() method.Exampleimport numpy as np from matplotlib import pyplot as plt # Set the figure size plt.rcParams["figure.figsize"] ... Read More

5K+ Views
To visualize values on logarithmic scale on matplotlib, we can use yscale('log').StepsImport matplotlib nd numpy.Set the figure size and adjust the padding between and around the subplots.Create x and y data points using numpy.Use yscale('log') to visualize the values on a logarithmic scale.Plot x and y data points using plot method.Place a legend on the figure.To display the figure, use show() method.Exampleimport numpy as np from matplotlib import pyplot as plt # Set the figure size plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True # x and y data points x = np.linspace(1, 100, 1000) y = np.log(x) ... Read More

44K+ Views
To change the font size of xticks in a matplotlib plot, we can use the fontsize parameter.StepsImport matplotlib and numpy.Set the figure size and adjust the padding between and around the subplots.Create x and y data points using numpy.Plot the x and y data points using plot() method.Set the font size of xticks using xticks() method.To display the figure, use show() method.Examplefrom matplotlib import pyplot as plt import numpy as np # Set the figure size plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True # x and y data points x = np.linspace(-5, 5, 100) y = np.sin(x) ... Read More

3K+ Views
To plot multiple horizontal bars in one chart with matplotlib, we can take the following steps −StepsImport the libraries pandas, matplotlib, and numpy.Set the figure size and adjust the padding between and around the subplots.Create an array for horizontal bar's position.Initialize a variable width for bar's width.Create a horizontal bar plot.Set Y-axis ticks and tick labels with some limit.Place a legend on the plot at the upper right location.To display the figure, use show() method.Exampleimport pandas import matplotlib.pyplot as plt import numpy as np # Set the figure size plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True # Array ... Read More

2K+ Views
To shift the colorbar position to right in matplotlib, we can take the following steps −StepsImport numpy and matplotlib.Set the figure size and adjust the padding between and around the subplots.Initialize a variable N to store the number of sample data.Create x and y data points using numpy.Create a scatter plot using scatter() method with x and y data points.Add a colorbar to a plot, use the pad value for horizontal shift towards right or left.To display the figure, use show() method.Example# Import numpy and matplotlib import numpy as np from matplotlib import pyplot as plt # Set the ... Read More

2K+ Views
To set the value of the axis multiplier in matplotlib, we can take the following steps −StepsSet the figure size and adjust the padding between and around the subplots.Create x data points using numpy.Plot x and x2 using plot() method.Get the current axis of the figure.Initialize a variable multiplier, i.e., a value of the axis multiplier.Set a tick on each integer multiple of a base within the view interval.Set the locator of the major ticker.To display the figure, use show() method.Example# Import matplotlib and numpy from matplotlib import pyplot as plt import numpy as np # Set the figure ... Read More

5K+ Views
The interp1d() function of scipy.interpolate package is used to interpolate a 1-D function. It takes arrays of values such as x and y to approximate some function y = f(x) and then uses interpolation to find the value of new points.Syntaxscipy.interpolate.interp1d(x, y)where x is a 1-D array of real values and y is an N-D array of real values. The length of y along the interpolation axis must be equal to the length of x.Example 1Let us consider the following example −# Import the required libraries import matplotlib.pyplot as plt import numpy as np from scipy import interpolate # ... Read More

227 Views
The tanm() function of scipy.linalg package is used to compute the tangent of an input matrix. This routine uses expm to compute the matrix exponentials.Syntaxscipy.linalg.tanm(x)where x is the input array or a square matrix. It returns the matrix tangent of x.Example 1Let us consider the following example −# Import the required libraries from scipy import linalg import numpy as np # Define the input array x = np.array([[69 , 12] , [94 , 28]]) print("Input array: ", x) # Calculate the Tangent a = linalg.tanm(x) # Display the Tangent of matrix print("Tangent of X: ", a)OutputIt will ... Read More

218 Views
The cosm() function of scipy.linalg package is used to compute the cosine of an input matrix. This routine uses expm to compute the matrix exponentials.Syntaxscipy.linalg.cosm(x)where x is the input array.Example 1Let us consider the following example −# Import the required libraries from scipy import linalg import numpy as np # Define the input array q = np.array([[121 , 10] , [77 , 36]]) print("Array Input :", q) # Calculate the Cosine r = linalg.cosm(q) # Display the Cosine of matrix print("Cosine of Q: ", r)OutputThe above program will generate the following output − Array Input : ... Read More

231 Views
The sinm() function scipy.linalg package is used to compute the sine of an input matrix. This routine uses expm to compute the matrix exponentials.Syntaxscipy.linalg.sinm(x)where x is the inputer array.Example 1Let us consider the following example −# Import the required libraries from scipy from scipy import linalg import numpy as np # Define the input array X = np.array([[110, 12], [79, 23]]) print("Input Matrix, X:", X) # Calculate the Sine of the matrix n = linalg.sinm(X) # Display the Sine print("Sine of X: ", n)OutputIt will generate the following output − Input Matrix, X: [[110 12] ... Read More