Found 784 Articles for Data Visualization

How to add bold annotated text in Matplotlib?

Rishikesh Kumar Rishi
Updated on 03-Jun-2021 12:31:26

1K+ Views

To add bold annotated text in matplotlib, we can use LaTeX representation for labels.StepsSet the figure size and adjust the padding between and around the subplots.Create x and y data points using numpy.To set the label for each scattered point, make a list of labels.Plot xpoints, ypoints using scatter() method. For color, use xpoints.Iterate zipped labels, xpoints and ypoints.Use annotate() method with bold LaTeX representation insie the for loop.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 xpoints = np.linspace(1, 10, 10) ypoints = np.random.rand(10) labels ... Read More

How to plot half or quarter polar plots in Matplotlib?

Rishikesh Kumar Rishi
Updated on 03-Jun-2021 12:29:13

971 Views

To plot half or quarter polar plots in Matplotlib, 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.Add an axes to the figure as part of a subplot arrangement.For half or quarter polar plots, use set_thetamax() method.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 fig = plt.figure() ax = fig.add_subplot(111, projection="polar") max_theta = 90 ax.set_thetamax(max_theta) plt.show()OutputRead More

How to plot a point on 3D axes in Matplotlib?

Rishikesh Kumar Rishi
Updated on 03-Jun-2021 12:27:54

5K+ Views

To plot a point on 3D axes in Matplotlib, 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.Add an axes to the figure as part of a subplot arrangement, with 3d projection.To plot a point in 3d axes, use scatter() method.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 fig = plt.figure() ax = fig.add_subplot(111, projection='3d') ax.scatter(2, 3, 4, c='red', marker='*', s=1000) plt.show()OutputRead More

How to display a Dataframe next to a Plot in Jupyter Notebook?

Rishikesh Kumar Rishi
Updated on 03-Jun-2021 12:25:18

1K+ Views

To display a dataframe next to a plot, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Make a Pandas dataframe with straight and square keys.Create a new figure or activate an existing figure using figure() method.Add a subplot to the figure with nrows=1, cols=2 and index=1.Plot dataframe points using scatter() method.Add subplot to the figure with nrows=1, cols=2 and index=2.Initialize variables font_size, bbox to make a table.Turn off the current axes.Add a table to the current axis using table() method.To display the figure, use show() method.Exampleimport matplotlib.pyplot as plt import ... Read More

Plotting histograms against classes in Pandas / Matplotlib

Rishikesh Kumar Rishi
Updated on 03-Jun-2021 12:22:58

201 Views

To plot histograms against classes in Pandas/Matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Make a potentially hetrogeneous tabular data using Pandas dataframe.Make a histogram from the DataFrame values.To display the figure, use show() method.Examplefrom 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({'a': [1, 1, 1, 1, 3],'b': [1, 1, 2, 1, 3],'c': [2, 2, 2, 1, 3],    'd': [2, 1, 2, 1, 3],}) df.hist() plt.show()Output

How to plot a Bar Chart with multiple labels in Matplotlib?

Rishikesh Kumar Rishi
Updated on 03-Jun-2021 12:21:31

2K+ Views

To plot a bar chart with multiple labels in Matplotlib, we can take the following steps −Make some data set for men_means, men_std, women_means, and women_std.Make index data points using numpy.Initialize the width of the bars.Use subplots() method to create a figure and a set of subplots.Create rects1 and rects2 bars rectangle using bar() method.Use set_ylabel(), set_title(), set_xticks() and set_xticklabels() methods.Place a legend on the plot.Add multiple labels for bar chart using autolabel() 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 men_means, men_std = (20, ... Read More

Rotating axes label text in 3D Matplotlib

Rishikesh Kumar Rishi
Updated on 03-Jun-2021 12:17:23

3K+ Views

To rotate axes label text in 3D matplotlib, we can use set_zlabel() method with rotation in the method's argument.StepsSet the figure size and adjust the padding between and around the subplots.Create a new figure or activate an existing figure using figure() method.Add a subplot to the current axis with projection="3d".Initialize a variable, angle, for an angle.Set Z-axis label using set_zlabel() method with a rotation.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 fig = plt.figure() ax = fig.add_subplot(111, projection='3d') angle = 45 ax.set_zlabel('Z-Axis', rotation=angle) plt.show()OutputRead More

Drawing multiple legends on the same axes in Matplotlib

Rishikesh Kumar Rishi
Updated on 03-Jun-2021 10:13:58

8K+ Views

To draw multiple legends on the same axes in Matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplotsPlot lines using two lists with different labels, linewidth and linestyle.Place the first legend at the upper-right location.Add artist, i.e., first legend on the current axis.Place the second legend on the current axis at the lower-right location.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 line1, = plt.plot([1, 2, 3], label="Line 1", linestyle='--') line2, = plt.plot([3, 2, 1], label="Line 2", ... Read More

Best way to plot an angle between two lines in Matplotlib

Rishikesh Kumar Rishi
Updated on 03-Jun-2021 10:12:07

2K+ Views

The best way to plot an angle between two lines in Matplotlib is to use the Arc class to make an angle arc to plot the angle in between.StepsSet the figure size and adjust the padding between and around the subplots.Create a new figure or activate an existing figure using figure() method.Add an '~.axes.Axes' to the figure as part of a subplot arrangement using add_subplot() method.Create 2D line instances as l1 and l2.Add lines to the current axes.To plot an angle, call a user-defined method that returns an elliptical arc. Arc length could be created using slopes of the lines..Add an ... Read More

How to display percentage above a bar chart in Matplotlib?

Rishikesh Kumar Rishi
Updated on 03-Jun-2021 10:07:46

3K+ Views

To display percentage above a bar chart 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; initialize a variable, width.Create a figure and a set of subplots using subplots() method.Add bars with x and y data points.Iterate bars patches; put text over the bars using text() method.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 = [1, 2, 3, 4, 5] y = [3, 4, 2, ... Read More

Advertisements