Found 784 Articles for Data Visualization

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

How to extract only the month and day from a datetime object in Python?

Rishikesh Kumar Rishi
Updated on 23-Sep-2021 08:51:27

1K+ Views

To extract only the month and day from a datetime object in Python, we can use the DateFormatter() class.stepsSet 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.Create a figure and a set of subplots.Plot the dataframe using plot() method.Set the axis formatter, extract month and day.To display the figure, use show() method.Exampleimport numpy as np import pandas as pd from matplotlib import pyplot as plt, dates plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True df = pd.DataFrame(dict(time=list(pd.date_range("2021-01-01 12:00:00", periods=10)), speed=np.linspace(1, 10, 10))) fig, ax = ... Read More

How to remove the first and last ticks label of each Y-axis subplot in Matplotlib?

Rishikesh Kumar Rishi
Updated on 23-Sep-2021 08:56:18

2K+ Views

To remove the first and last ticks label of each Y-axis subplot, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create a figure and a set of subplots.Iterate the axes and set the first and last ticklabel's visible=False.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(2, sharex=True) for a in ax:    plt.setp(a.get_yticklabels()[0], visible=False)    plt.setp(a.get_yticklabels()[-1], visible=False) plt.show()OutputRead More

Advertisements