Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

1,016 Articles Published

Articles by Rishikesh Kumar Rishi

Page 21 of 102

How to make multipartite graphs using networkx and Matplotlib?

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 10-Aug-2021 2K+ Views

To make multipartite graph in networkx, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create a list of subset sizes and colors.Define a method for multilayered graph that could return a multilayered graph object.Set the color of the nodes.Position the nodes in layers of straight lines.Draw the graph G with Matplotlib.Set equal axis properties.To display the figure, use show() method.Exampleimport itertools import matplotlib.pyplot as plt import networkx as nx plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True subset_sizes = [5, 5, 4, 3, 2, 4, 4, 3] subset_color = ...

Read More

How to plot the difference of two distributions in Matplotlib?

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 10-Aug-2021 2K+ Views

To plot the difference of two distributions in Matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create a and b datasets using Numpy.Get kdea and kdeb, i.e., representation of a kernel-density estimate using Gaussian kernels.Create a grid using Numpy.Plot the gird with kdea(grid), kdeb(grid) and kdea(grid)-kdeb(grid), using plot() method.Place the legend at the upper-left corner.To display the figure, use show() method.Exampleimport numpy as np import matplotlib.pyplot as plt import scipy.stats plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True a = np.random.gumbel(50, 28, 100) b = np.random.gumbel(60, 37, 100) ...

Read More

How to visualize 95% confidence interval in Matplotlib?

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 10-Aug-2021 8K+ Views

To visualize 95% confidence interval in Matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create x and y data sets.Get the confidence interval dataset.Plot the x and y data points using plot() method.Fill the area within the confidence interval range.To display the figure, use show() method.Examplefrom matplotlib import pyplot as plt import numpy as np plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True x = np.arange(0, 10, 0.05) y = np.sin(x) # Define the confidence interval ci = 0.1 * np.std(y) / np.mean(y) plt.plot(x, y, color='black', ...

Read More

Plotting an imshow() image in 3d in Matplotlib

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 10-Aug-2021 5K+ Views

To plot an imshow() image in 3D in Matplotlib, we can take the following steps −Create xx and yy data points using numpy.Get the data (2D) using X, Y and Z.Create a new figure or activate an existing figure using figure() method.Add an 'ax1' to the figure as part of a subplot arrangement.Display the data as an image, i.e., on a 2D regular raster with data.Add an 'ax2' to the figure as part of a subplot arrangement.Create and store a set of contour lines or filled regions.To display the figure, use show() method.Exampleimport matplotlib.pyplot as plt import numpy as np ...

Read More

Adding extra contour lines using Matplotlib 2D contour plotting

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 10-Aug-2021 1K+ Views

To add extra contour lines using Matplotlib 2D contour plotting, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create e a function f(x, y) to get the z data points from x and y.Create x and y data points using numpy.Make a list of levels using Numpy.Make a contour plot using contour() method.Label the contour plot and set the title of the plot.To display the figure, use show() method.Exampleimport matplotlib.pyplot as plt import numpy as np plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True def f(x, y):    return ...

Read More

How to remove the digits after the decimal point in axis ticks in Matplotlib?

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 10-Aug-2021 8K+ Views

To remove the digits after the decimal point in axis ticks in Matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create x and y data points using numpy.Create a figure and a set of subplots.To set the xtick labels only in digits, we can use x.astype(int) method.To display the figure, use show() method.Exampleimport matplotlib.pyplot as plt import numpy as np plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True x = np.array([1.110, 2.110, 4.110, 5.901, 6.00, 7.90, 8.90]) y = np.array([2.110, 1.110, 3.110, 9.00, 4.001, 2.095, 5.890]) fig, ...

Read More

Hiding major tick labels while showing minor tick labels in Matplotlib

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 10-Aug-2021 966 Views

To hide major tick labels while showing minor ticklabels in Matplotlib, we can take the following steps −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.Set a property on an artist object, using setp() method.To display the figure, use show() method.Exampleimport matplotlib.pyplot as plt import numpy as np plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True x = np.linspace(1, 10, 100) y = np.log(x) plt.plot(x, y) plt.setp(plt.gca().get_xmajorticklabels(), visible=False) plt.show()Output

Read More

How to mark a specific level in a contour map on Matplotlib?

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 10-Aug-2021 1K+ Views

To mark a specific level in a contour map on Matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create x, y and z data points using Numpy.Use contour() method to make contour plot.Label the contour plot.To display the figure, use show() method.Exampleimport matplotlib.pyplot as plt import numpy as np plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True def f(x, y):    return np.sin(x) ** 10 + np.cos(10 + y * x) * np.cos(x) x = np.linspace(0, 5, 50) y = np.linspace(0, 5, 40) X, Y = ...

Read More

How to label a patch in matplotlib?

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 10-Aug-2021 3K+ Views

To label a patch in matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Initialize the center of the rectangle patch.Create a new figure or activate an existing figure.Add an 'ax' to the figure as part of a subplot arrangement.Add a 'rectangle' to the axes' patches; return the patch.Place a legend on the figure.To display the figure, use show() method.Exampleimport matplotlib.pyplot as plt import matplotlib.patches as patches plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True x = y = 0.1 fig = plt.figure() ax = fig.add_subplot(111) patch = ...

Read More

How to sort bars in a bar plot in ascending order (Matplotlib)?

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 10-Aug-2021 15K+ Views

To sort bars in a bar plot in ascending order, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Make a list of data for bar plots.Create a bar plot using bar() method, with sorted data.To display the figure, use show() method.Examplefrom matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True data = [3, 5, 9, 15, 12] plt.bar(range(len(data)), sorted(data), color='red', alpha=0.5) plt.show()Output

Read More
Showing 201–210 of 1,016 articles
« Prev 1 19 20 21 22 23 102 Next »
Advertisements