Found 1014 Articles for Matplotlib

How do I remove the Y-axis from a Pylab-generated picture?

Rishikesh Kumar Rishi
Updated on 02-Feb-2022 10:40:17
To remove the Y-axis from a Pylab-generated picture, we can get the current axis of the plot and use the set_visible(False) method.StepsSet the figure size and adjust the padding between and around the subplots.Create x and y data points using numpy.Plot the x and y data points using plot() method.Get the current axis of the current figure.Set the visibility to False for the Y-axis.To display the figure, use show() method.Exampleimport numpy as np import pylab # Set the figure size pylab.rcParams["figure.figsize"] = [7.50, 3.50] pylab.rcParams["figure.autolayout"] = True # Random data points x = np.random.rand(10) y = np.random.rand(10) ... Read More

Flushing all current figures in matplotlib

Rishikesh Kumar Rishi
Updated on 02-Feb-2022 10:33:33
To flush all current figures in matplotlib, use close('all') method.StepsSet the figure size and adjust the padding between and around the subplots.Create a figure with the title "First Figure".Create another figure with the title "Second Figure".To close all figures, use close('all').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.figure("First Figure") plt.figure("Second Figure") # plt.close('all') plt.show()OutputNotice that we have commented the line −plt.close('all') Hence, it will display two figures −Uncomment the line plt.close('all') and run the code again. It will flush all the current figures.Read More

How to create multiple series scatter plots with connected points using seaborn?

Rishikesh Kumar Rishi
Updated on 02-Feb-2022 10:28:25
To create multiple series scatter plots with connected points using seaborn, we can take the following steps −StepsSet the figure size and adjust the padding between and around the subplots.Create a Pandas data frame of two-dimensional, size-mutable, potentially heterogeneous tabular data.Multi-plot grid for plotting conditional relationships.Apply a plotting function to each facet's subset of the data.Plot the scatter and the data points with x and y data points.To display the figure, use show() method.Exampleimport pandas as pd import seaborn as sns from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True df = pd.DataFrame({"x": [4, ... Read More

How to make a histogram with bins of equal area in Matplotlib?

Rishikesh Kumar Rishi
Updated on 02-Feb-2022 10:13:04
To make a histogram with bins of equal area in matplotlib, we can take the following steps −StepsSet the figure size and adjust the padding between and around the subplots.Create random data points using numpy.Plot a histogram with equal_area method that makes an equal area of the patches.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 def equal_area(x, nbin):    pow = 0.5    dx = np.diff(np.sort(x))    tmp = np.cumsum(dx ** pow)    tmp = np.pad(tmp, (1, 0), 'constant')    return np.interp(np.linspace(0, tmp.max(), ... Read More

Combining two heatmaps in seaborn

Rishikesh Kumar Rishi
Updated on 02-Feb-2022 10:08:49
To combine two heatmaps in seaborn, we can take the following steps −StepsSet the figure size and adjust the padding between and around the subplots.Create two Pandas data frames.Create a figure and a set of subplots, ax1 and ax2.Plot the rectangular data as a color-encoded matrix, on ax1 and ax2.Move ticks and ticklabels (if present) to the right of the axes.Keep the width of the padding between subplots minimum, as a fraction of the average axes width.To display the figure, use show() method.Exampleimport matplotlib.pyplot as plt import numpy as np import pandas as pd import seaborn as sns plt.rcParams["figure.figsize"] ... Read More

Boxplot stratified by column in Python Pandas

Rishikesh Kumar Rishi
Updated on 02-Feb-2022 10:06:50
To create a boxplot stratified by column in Python class, we can take the following steps −StepsSet the figure size and adjust the padding between and around the subplots.Create a Pandas data frame of two-dimensional, size-mutable, potentially heterogeneous tabular data.Compute the histogram of a set of data.Create a boxplot startified by column.To display the figure, use show() method.Exampleimport pandas as pd import numpy as np from matplotlib import pyplot as plt # Set the figure size plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True # Pandas dataframe df = pd.DataFrame({"column1": [4, 6, 7, 1, 8], "column2": [1, 5, 7, ... Read More

How to plot aggregated by date pandas dataframe?

Rishikesh Kumar Rishi
Updated on 02-Feb-2022 10:01:27
To plot aggregated by date pandas dataframe, we can take the following steps −StepsSet the figure size and adjust the padding between and around the subplots.Create a data frame, df, of two-dimensional, size-mutable, potentially heterogeneous tabular data.Get the values of aggregated by date pandas dataframe.Plot the df (Step 3) with kind="bar".To display the figure, use show() method.Exampleimport numpy as np import pandas as pd from matplotlib import pyplot as plt, dates # Set the figure size plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True # Create a dataframe df = pd.DataFrame(dict(data=list(pd.date_range("2021-01-01", periods=10)), value=np.linspace(1, 10, 10))) df = df.groupby('data').agg(['sum']).reset_index() ... Read More

How to vary the line color with data index for line graph in matplotlib?

Rishikesh Kumar Rishi
Updated on 02-Feb-2022 09:49:55
To have the line color vary with the data index for a line graph in matplotlib, we can take the following steps −StepsSet the figure size and adjust the padding between and around the subplots.Create x and y data points using numpy.Get smaller limit, dydx.Get the points and segments data points using numpy.Create a figure and a set of subplots.Create a class which, when called, linearly normalizes data into some range.Set the image array from numpy array *A*.Set the linewidth(s) for the collection.Set the colorbar for axis 1.Generate Colormap object from a list of colors i.e r, g and b.Repeat ... Read More

How can I format a float using matplotlib's LaTeX formatter?

Rishikesh Kumar Rishi
Updated on 01-Feb-2022 12:18:00
To format a float using matplotlib's LaTeX formatter, we can take the following steps −StepsSet the figure size and adjust the padding between and around the subplots.Create x and y data points using numpy.Plot the x and y data points using plot() method.Fill the area between the curve.Set the title of the figure with LaTeX representation.To display the figure, use show() method.Exampleimport numpy as np from matplotlib import pyplot as plt # Set the figures size plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True # x and y data points x = np.linspace(-5, 5, 100) y = x**3/3 ... Read More

How to set local rcParams or rcParams for one figure in matplotlib?

Rishikesh Kumar Rishi
Updated on 01-Feb-2022 12:14:03
To set local rcParams or rcParams for one figure in matplotlib, we can take the following steps −StepsSet the figure size and adjust the padding between and around the subplots.Initialize a variable N to store the number of sample data.Create x and y data points using numpy.Return a context manager for temporarily changing rcParams.Add a subplot to the current figure, at index 1.Plot the x and y data points, using plot() method.Add a subplot to the current figure, at index 2.Plot the x and y data points, using plot() method.To display the figure, use show() method.Exampleimport pandas as pd import ... Read More
Advertisements