- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 1007 Articles for Matplotlib

Updated on 02-Feb-2022 10:51:20
To set the xticklabels for date in matplotlib, we can take the following steps −StepsSet the figure size and adjust the padding between and around the subplots.Create two lists of epochs and values.Get a list of dates from epochs.Create a figure and a set of subplots.Plot the date and values using plot() method.Set the xticklabels, get date formatter and set the major formatter.To remove the overlapping for ticklabels, rotate it by 10.To display the figure, use show() method.Exampleimport matplotlib.pyplot as plt import matplotlib.dates as mdates import time plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True epochs = [1259969793926, 1259969793927, ... Read More 
Updated on 02-Feb-2022 10:47:22
To scatter a 2D numpy array in matplotlib, we can take the following steps −StepsSet the figure size and adjust the padding between and around the subplots.Create random data of 100×3 dimension.Use the scatter() method to plot 2D numpy array, i.e., data.To display the figure, use show() method.Exampleimport 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 # Random data of 100×3 dimension data = np.array(np.random.random((100, 3))) # Scatter plot plt.scatter(data[:, 0], data[:, 1], c=data[:, 2], cmap='hot') # Display the plot plt.show()OutputIt will produce ... Read More 
Updated on 02-Feb-2022 10:44:17
To avoid overlapping error bars in matplotlib, we can take the following steps −StepsSet the figure size and adjust the padding between and around the subplots.Create a list of names.Get the data points for y1 and y2, and errors ye1, ye2.Create a figure and a set of subplots.Create a mutable 2D affine transformation, trans1 and trans2.Plot y versus x as lines and/or markers with attached errorbars.To display the figure, use show() method.Exampleimport numpy as np import matplotlib.pyplot as plt from matplotlib.transforms import Affine2D plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True x = ['Jack', 'James', 'Tom', 'Garry'] y1, ... Read More 
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 
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 
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 
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 
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 
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 
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 Advertisements