Found 784 Articles for Data Visualization

How to decrease the hatch density in Matplotlib?

Rishikesh Kumar Rishi
Updated on 23-Sep-2021 10:33:17

542 Views

To decrease the hatch density in Matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Make a customized horizontal hatch class to override the density.Append the horizontal hatch class.Create a new figure or activate an existing figure.Add an 'ax1' to the figure as part of a subplot arrangement.Make lists of data points.Make a bar plot with x and ydata points, with hatch='o', color='green' and edgecolor='red'.To display the figure, use show() method.Examplefrom matplotlib import pyplot as plt, hatch plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True class MyHorizontalHatch(hatch.HorizontalHatch):    def ... Read More

How to make a quiver plot in polar coordinates using Matplotlib?

Rishikesh Kumar Rishi
Updated on 23-Sep-2021 10:55:51

2K+ Views

To make a quiver plot in polar coordinates using Matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create radii, thetas, theta and r data points using numpy.Create a new figure or activate an existing figure.Add an 'ax' to the figure as part of a subplot arrangement.Make poly collections of arrows.To display the figure, use show() method.Exampleimport numpy as np from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True radii = np.linspace(0, 1, 5) thetas = np.linspace(0, 2 * np.pi, 20) theta, r = ... Read More

How to have a function return a figure in Python (using Matplotlib)?

Rishikesh Kumar Rishi
Updated on 23-Sep-2021 11:07:08

13K+ Views

To have a function return a figure in Python (using 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.Make a function plot(x, y) that creates a new figure or activate an existing figure using figure() method.Plot the x and y data points using plot() method; return fig instance.Call plot(x, y) method and store the figure instance in a variable, f.To display the figure, use show() method.Exampleimport numpy as np from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = ... Read More

What is the correct way to replace matplotlib tick labels with computed values?

Rishikesh Kumar Rishi
Updated on 23-Sep-2021 11:08:28

268 Views

We can use ax.loglog(x, y) and set_major_formatter() methods to replace tick labels with computed values.StepsSet the figure size and adjust the padding between and around the subplots.Create a figure and a set of subplots.Make a plot with log scaling on both the X and Y axis.Set the formatter of the major ticker.To display the figure, use show() method.Exampleimport numpy as np from matplotlib import pyplot as plt, ticker plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True fig, ax = plt.subplots() ax.loglog(np.logspace(0, 5), np.logspace(0, 5)**2) ax.xaxis.set_major_formatter(ticker.LogFormatterExponent()) plt.show()OutputRead More

How to make a simple lollipop plot in Matplotlib?

Rishikesh Kumar Rishi
Updated on 23-Sep-2021 11:10:59

375 Views

To make a simple lollipop plot in Matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Make a dataframe, df, of two-dimensional, size-mutable, potentially heterogeneous tabular data.Make an ordered dataframe, using sort_values().Make a list in the range of dataframe index.Create a stem plot, using the ordered dataframe.Set xticks and labels using xticks() method.To display the figure, use show() method.Exampleimport numpy as np from matplotlib import pyplot as plt import pandas as pd plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True df = pd.DataFrame({'group': list(map(chr, range(65, 85))), 'values': np.random.uniform(size=20)}) ... Read More

How to put the title at the bottom of a figure in Matplotlib?

Rishikesh Kumar Rishi
Updated on 23-Sep-2021 11:12:10

6K+ Views

To put the line title at the bottom of a figure in Matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Initialize a variable, N, to get the number of sample data.Plot the x and y data points using scatter() method.Set the title at the bottom of the figure in matplotlib, with y=-0.01.To display the figure, use show() method.Exampleimport numpy as np from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True N = 100 x = np.random.rand(N) y = np.random.rand(N) plt.scatter(x, y, c=x, ... Read More

How to make multipartite graphs using networkx and Matplotlib?

Rishikesh Kumar Rishi
Updated on 10-Aug-2021 07:20:47

1K+ 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
Updated on 10-Aug-2021 07:19:23

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

What exactly is a Matplotlib axes object?

Rishikesh Kumar Rishi
Updated on 10-Aug-2021 07:18:18

230 Views

The Axes class contains most of the figure elements − Axis, Tick, Line2D, Text, Polygon, etc., and sets the coordinate system.stepsSet the figure size and adjust the padding between and around the subplots.Set the axes linewidth using rcParams.Add an axes to the current figure and make it the current axes.Set the axes spines color.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 plt.rcParams['axes.linewidth'] = 5 ax = plt.axes() ax.spines['bottom'].set_color('yellow') ax.spines['top'].set_color('red') ax.spines['right'].set_color('black') ax.spines['left'].set_color('blue') plt.show()OutputRead More

How to visualize 95% confidence interval in Matplotlib?

Rishikesh Kumar Rishi
Updated on 10-Aug-2021 07:16:53

7K+ 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

Advertisements