Found 10476 Articles for Python

How to avoid line color repetition in matplotlib.pyplot?

Rishikesh Kumar Rishi
Updated on 01-Feb-2022 11:23:09

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

How to visualize values on logarithmic scale on matplotalib?

Rishikesh Kumar Rishi
Updated on 01-Feb-2022 11:20:03

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

How to change xticks font size in a matplotlib plot?

Rishikesh Kumar Rishi
Updated on 08-Sep-2023 23:25:53

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

How to plot multiple horizontal bars in one chart with matplotlib?

Rishikesh Kumar Rishi
Updated on 01-Feb-2022 11:14:19

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

How to shift the colorbar position to right in matplotlib?

Rishikesh Kumar Rishi
Updated on 01-Feb-2022 11:11:11

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

How to set the value of the axis multiplier in matplotlib?

Rishikesh Kumar Rishi
Updated on 01-Feb-2022 11:07:43

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

Python – scipy.interpolate.interp1d

Syed Abeed
Updated on 24-Dec-2021 10:25:39

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

Python – scipy.linalg.tanm()

Syed Abeed
Updated on 24-Dec-2021 10:12:31

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

Python – scipy.linalg.cosm

Syed Abeed
Updated on 24-Dec-2021 10:10:45

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

Python – scipy.linalg.sinm()

Syed Abeed
Updated on 24-Dec-2021 10:08:49

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

Advertisements