Found 784 Articles for Data Visualization

How to make a broken horizontal bar plot in Matplotlib?

Rishikesh Kumar Rishi
Updated on 09-Jun-2021 12:08:34

614 Views

We can take the following steps to make a broken bar plot, Set the figure size and adjust the padding between and around the subplots.Create a figure and a set of subplots.Plot a horizontal sequence of rectangles.Set x and y axes scale, X-axis label, Y ticks and Y tick labels.Configure the grid lines.Use annotate() method to show text that can refer to a specific position.To display the figure, use show() method.Exampleimport matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True fig, ax = plt.subplots() ax.broken_barh([(110, 30), (150, 10)], (10, 9), facecolors='tab:blue') ax.broken_barh([(10, 50), (100, 20), (130, ... Read More

Plot curves in fivethirtyeight stylesheet in Matplotlib

Rishikesh Kumar Rishi
Updated on 09-Jun-2021 12:13:40

373 Views

To use fivethirtyeight stylesheet, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.To use fivethirtyeight, we can use plt.style.use() method.Create x data points using numpy.Create a figure and a set of subplots using subplots() method.Plot three curves using plot() method.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 plt.style.use('fivethirtyeight') x = np.linspace(0, 10) fig, ax = plt.subplots() ax.plot(x, np.sin(x) + x + np.random.randn(50)) ax.plot(x, np.sin(x) + 0.5 * x + ... Read More

How to update the plot title with Matplotlib using animation?

Rishikesh Kumar Rishi
Updated on 09-Jun-2021 12:08:03

2K+ Views

To update the plot title with Matplotlib using animation, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create a new figure or activate an existing figure using figure() method.Create x and y data points using numpy.Get the current axis.Add text to the axes using text() method.Add an animate method that can be used to make an animation by repeatedly calling a function.To display the figure, use show() method.Exampleimport numpy as np from matplotlib import pyplot as plt, animation plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True fig = plt.figure() ... Read More

Colouring the edges by weight in networkx (Matplotlib)

Rishikesh Kumar Rishi
Updated on 09-Jun-2021 12:03:59

3K+ Views

To color the edges by weight in networkx, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Initialize a graph with edges, name, or graph attributes.Add nodes to the current graph.Add edges to the current graph's nodes.Iterate the given graph's edges and set some weight to them.Draw current graphs with weights for edge color.To display the figure, use show() method.Exampleimport random as rd import matplotlib.pylab as plt import networkx as nx plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True G = nx.DiGraph() G.add_nodes_from([1, 2, 3, 4]) G.add_edges_from([(1, 2), (2, 3), ... Read More

Plotting animated quivers in Python using Matplotlib

Rishikesh Kumar Rishi
Updated on 09-Jun-2021 12:03:35

2K+ Views

To animate quivers in Python, 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 u and v data points using numpy.Create a figure and a set of subplots.Plot a 2D field of arrows using quiver() method.To animate the quiver, we can change the u and v values, in animate() method. Update the u and v values and the color of the vectors.To display the figure, use show() method.Exampleimport numpy as np import random as rd from matplotlib import pyplot as plt, animation ... Read More

How to make markers on lines smaller in Matplotlib?

Rishikesh Kumar Rishi
Updated on 09-Jun-2021 12:03:14

1K+ Views

To make markers on lines smaller in Matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create random data points, x.Plot x data points using plot() method, with linewidth =0.5 and color="black".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.random.rand(20) plt.plot(x, '*-', color='black', markersize=10, lw=0.5) plt.show()Output

Adjusting the heights of individual subplots in Matplotlib in Python

Rishikesh Kumar Rishi
Updated on 09-Jun-2021 12:02:55

953 Views

To adjust the heights of individual subplots in Matplotlib in Python, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Add a subplot to the current figure, nrows=7, ncols=2 and at index=1.Add a subplot to the current figure, nrows=2, ncols=2 and at index=3Add a subplot to the current figure, nrows=1, ncols=3 and at index=3To display the figure, use show() method.Exampleimport matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True plt.subplot(7, 2, 1) plt.subplot(2, 2, 3) plt.subplot(1, 3, 3) plt.show()Output

How to import Matplotlib in Python?

Rishikesh Kumar Rishi
Updated on 23-Aug-2023 14:11:54

70K+ Views

First of all, make sure you have python and pip preinstalled on your system. To check Python version, typepython --versionTo check pip version, typepip −VThen, run the following pip command in the command prompt to install Matplotlib.pip install matplotlibTo verify that matplotlib is successfully installed on your system, execute the following command in the command prompt.import matplotlib matplotlib.__version__If matplotlib is successfully installed, the version of matplotlib will be displayed.Now, let us import Matplotlib and plot some random data points.StepsImport matplotlib.Set the figure size and adjust the padding between and around the subplots.Create random data points, x.Plot x using plot() method.To ... Read More

How can I make Matplotlib.pyplot stop forcing the style of my markers?

Rishikesh Kumar Rishi
Updated on 09-Jun-2021 11:43:49

98 Views

To make matplotlib.pyplot stop forcing the style of markers, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create random x and y data points using numpy.Plot x and y data points using plot() method, with "r*" marker with markersize=10.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.random.rand(20) y = np.random.rand(20) plt.plot(x, y, 'r*', markersize=10) plt.show()Output

Setting the limits on a colorbar of a contour plot in Matplotlib

Rishikesh Kumar Rishi
Updated on 09-Jun-2021 11:43:15

10K+ Views

To set the limits on a colorbar of a countour plot 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.Get the data using x and y.Get the coordinate matrices from the coordinate vectors.Initialize vmin and vmax to set the limits on a colorbar of a contour plot in matplotlib.Plot contours using contourf() method.Make the colorbar using scalar mappable within the range of vmin and vmax.To display the figure, use show() method.Examplefrom matplotlib import pyplot as plt import numpy as np from ... Read More

Advertisements