Found 1034 Articles for Matplotlib

How to draw axis lines inside a plot in Matplotlib?

Rishikesh Kumar Rishi
Updated on 20-Sep-2021 09:38:32

402 Views

To draw axis lines inside a plot 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.Create x data points using numpy.Add an 'ax' to the figure as part of a subplot arrangement.Plot x and x**x data points using plot() method.Set the left and bottom positions at 0, whereas color of the right and top spines none.To display the figure, use show() method.Exampleimport numpy as np import matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True fig = ... Read More

How to set same scale for subplots in Python using Matplotlib?

Rishikesh Kumar Rishi
Updated on 20-Sep-2021 09:32:07

3K+ Views

To set the same scale for subplot in Python using 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.Add an 'ax1' to the figure as part of a subplot arrangement with nrows=2, ncols=1 and index=1.Add another axis 'ax2' to the figure as part of a subplot arrangement with nrows=2, ncols=1 and index=2, with shared X-axis (to set same scale for subplots)Create "t" data points to plot sine and cosine curves on axes ax1 and ax2.To display the figure, use show() method.Exampleimport ... Read More

Conditional removal of labels in Matplotlib pie chart

Rishikesh Kumar Rishi
Updated on 20-Sep-2021 09:29:16

2K+ Views

To remove labels from a Matplotlib pie chart based on a condition, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create a Pandas dataframe of wwo-dimensional, size-mutable, potentially heterogeneous tabular data.Plot a pie chart, using pie() method with conditional removal of labels, such that if %age value is greater than 25, then only keep labels, otherwise remove them.To display the figure, use show() method.Exampleimport pandas as pd from matplotlib import pyplot as plt # Set the figure size plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True # Create a ... Read More

Matplotlib – Make a Frequency histogram from a list with tuple elements in Python

Rishikesh Kumar Rishi
Updated on 20-Sep-2021 09:23:49

2K+ Views

To make a frequency histogram from a list with tuple elements in Python, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Make a list of tuples, data.Make lists of frequency and indices, after iterating the data.Make a bar plot usig bar() method.To display the figure, use show() method.Exampleimport matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True data = [("a", 1), ("c", 3), ("d", 4), ("b", 2), ("e", 7), ("f", 3), ('g', 2)] ind = [] fre = [] for item in data: ... Read More

How to rotate a simple matplotlib Axes?

Rishikesh Kumar Rishi
Updated on 20-Sep-2021 09:18:12

9K+ Views

To rotate a simple matplotlib axes, we can take the following steps −Import the required packages −import matplotlib.pyplot as plt from matplotlib.transforms import Affine2D import mpl_toolkits.axisartist.floating_axes as floating_axesSet the figure size and adjust the padding between and around the subplots.Create a new figure or activate an existing figure.Make a tuple of axes extremes.Add a mutable 2D affine transformation, "t". Add a rotation (in degrees) to this transform in place.Add a transform from the source (curved) coordinate to target (rectilinear) coordinate.Add a floating axes "h" with the current figure with GridHelperCurveLinear() instance.Add an 'ax' to the figure as part of a ... Read More

How to add a 3d subplot to a matplotlib figure?

Rishikesh Kumar Rishi
Updated on 20-Sep-2021 09:09:37

3K+ Views

To add a 3D subplot to a matplotlib figure, 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.Create a new figure or activate an existing figure.Add an 'ax' to the figure as part of a subplot arrangement with projection='3d'.Plot x, y and z data points using plot() 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.00, 3.50] plt.rcParams["figure.autolayout"] = True # Create x, y and ... Read More

How to create a 100% stacked Area Chart with Matplotlib?

Rishikesh Kumar Rishi
Updated on 23-Sep-2021 08:03:50

940 Views

To create a 100% stacked Area Chart with Matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create a list of years.Make a dictionary, with list of population in respective years.Create a figure and a set of subplots.Draw a stacked Area Plot.Place a legend on the figure, at the location ''upper left''.Set the title, xlabel and ylabel.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 year = [1950, 1960, 1970, 1980, 1990, 2000, 2010, 2018] population_by_continent = {   ... Read More

How to understand Seaborn's heatmap annotation format?

Rishikesh Kumar Rishi
Updated on 23-Sep-2021 08:34:41

2K+ Views

To understand Seaborn's heatmap annotation format, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create a Pandas dataframe with five columns.Plot the rectangular data as a color-encoded matrix, fmt=".2%" represents the annotation format.To display the figure, use show() method.ExampleExampleimport seaborn as sns import pandas as pd import numpy as np import matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True df = pd.DataFrame(np.random.random((5, 5)), columns=["a", "b", "c", "d", "e"]) sns.heatmap(df, annot=True, annot_kws={"size": 7}, fmt=".2%") plt.show()OutputRead More

How to remove or hide X-axis labels from a Seaborn / Matplotlib plot?

Rishikesh Kumar Rishi
Updated on 12-Sep-2023 01:10:01

35K+ Views

To remove or hide X-axis labels from a Seaborn / Matplotlib plot, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Use sns.set_style() to set an aesthetic style for the Seaborn plot.Load an example dataset from the online repository (requires Internet).To hide or remove X-axis labels, use set(xlabel=None).To display the figure, use show() method.Examplefrom matplotlib import pyplot as plt import seaborn as sns plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True sns.set_style("whitegrid") tips = sns.load_dataset("tips") ax = sns.boxplot(x="day", y="total_bill", data=tips) ax.set(xlabel=None) plt.show()OutputRead More

How to remove whitespaces at the bottom of a Matplotlib graph?

Rishikesh Kumar Rishi
Updated on 23-Sep-2021 08:43:20

3K+ Views

To remove whitespaces at the bottom of a Matplotlib graph, we can use tight layout or autoscale_on=False.stepsSet the figure size and adjust the padding between and around the subplots.Create a new figure or activate an existing figure.Add an 'ax' to the figure as part of a subplot arrangement.Plot a list of data points using plot() 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, autoscale_on=False, xlim=(1, 5), ylim=(0, 10)) ax.plot([2, 5, 1, 2, 0, 7]) plt.show()OutputRead More

Advertisements