- 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 1034 Articles for Matplotlib
3K+ Views
To plot a multicolored line based on a condition in Python Matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create y data points using numpy.Make l and u data points to differentiate the colors.Plot the u and l data points using plot() method, with different colors.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 y = np.sin(np.linspace(-10, 10, 100)) u = y.copy() l = y.copy() u[u = 0] = np.nan plt.plot(u, color='red') ... Read More
154 Views
To create a Boxplot with Matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Make a list of xticks.Plot a boxplot with xticks data.Set xticks and xtick labels with 45° rotation.To display the figure, use show() method.Exampleimport seaborn as sns from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True xticks = [1, 4, 5, 2, 3] ax = sns.boxplot(xticks) ax.set_xticks(xticks) ax.set_xticklabels(["one", "two", "three", "four", "five"], rotation=45) plt.show()Output
205 Views
To plot histogram bins interpreted with different bins, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Make a list of data to plot in histogram.Add a subplot to the current figure, nrows=1, ncols=3 and index=1.Plot a histogram with data; bins is a number.Add a subplot to the current figure, nrows=1, ncols=3 and index=2.Plot a histogram with data; bins is an array.Add a subplot to the current figure, nrows=1, ncols=3 and index=3.Plot a histogram with data, bins is a string.Exampleimport matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True ... Read More
1K+ Views
To annotate points from a Pandas dataframe in Matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Make a two-dimensional, size-mutable, potentially heterogeneous tabular data, with x, y and textc columns.Plot the columns x and y data points, using plot() method.Concatenate Pandas objects along a particular axis with optional set logic along the other axes.Iterate the Pandas object.Place text for each plotted points using text() method.To display the figure, use show() method.Exampleimport pandas as pd import matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True df = ... Read More
18K+ Views
To show a bar and line graph on the same plot in matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Make a two-dimensional, size-mutable, potentially heterogeneous tabular data.Create a figure and a set of subplots.Plot the bar and line with the dataframe obtained from Step 2.To display the figure, use show() method.Exampleimport pandas as pd import matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True df = pd.DataFrame(dict(data=[2, 4, 1, 5, 9, 6, 0, 7])) fig, ax = plt.subplots() df['data'].plot(kind='bar', color='red') df['data'].plot(kind='line', marker='*', color='black', ms=10) ... Read More
691 Views
To plot blurred points 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 new figure.Add an ax1 to the figure as part of a subplot arrangement.First, we can make a marker, i.e., to be blurred.Set the X and Y axes scale, turn off the axes.Save the marker in a file, and load that image to be plotted after blurred.Close the previous figure, fig1.Create a new figure or activate an existing figure, fig2.Create random data points, x and y.Apply Gaussian filter, to ... Read More
886 Views
To create a Swarm Plot with Matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create a Pandas dataframe, i.e., a two-dimensional, size-mutable, potentially heterogeneous tabular data.Initialize the plotter, swarmplot.To plot the boxplot, use boxplot() method.To display the figure, use show() method.Exampleimport seaborn as sns import matplotlib.pyplot as plt import pandas as pd import numpy as np plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True data = pd.DataFrame({"Box1": np.arange(10), "Box2": np.arange(10)}) ax = sns.swarmplot(x="Box1", y="Box2", data=data, zorder=0) ... Read More
4K+ Views
To display the matrix value and colormap in Matplotlib, 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.Initialize max and min values for matrix.Plot the values of a 2D matrix or array as color-coded image.Iterate each cell of the color-code image and place value at the center.To display the figure, use show() method.Exampleimport numpy as np import matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True fig, ax = plt.subplots() min_val, max_val = 0, 5 matrix = np.random.randint(0, 5, size=(max_val, ... Read More
1K+ Views
To annotate a range of the X-axis in matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create xx and yy data points using numpy.Create a figure and a set of subplots.Plot xx and yy data points using plot() method.Set ylim of the axis.Use annotate method to place arrow heads and range tag name.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 xx = np.linspace(0, 10) yy = np.sin(xx) fig, ax = plt.subplots(1, 1) ... Read More
1K+ Views
To add annotated text in Matplotlib for several points, 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 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 in a 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) ... Read More