- 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
Axes.flat means a 1D iterator over the array. Let's take an example to see how to use axes.flat.StepsSet the figure size and adjust the padding between and around the subplots.Create a figure and a set of subplots using subplots() method.Create x and y data points using numpy.Use axes.flat and iterate all the axes (step 2).Plot x and y data points using plot() method.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 fig, axes = plt.subplots(nrows=2, ncols=3) x = np.random.rand(10) y = np.random.rand(10) for _, ax ... Read More
3K+ Views
To write text above the bars on a bar plot, we can take the following stepsSet the figure size and adjust the padding between and around the subplots.Create lists of year, population and x. Initialize a width variable.Create a figure and a set of subplots using subplots() method.Set ylabels, title, xtickas and xticklabels.Plot the bars using bar() method with x, population and width data.Iterate the bar patches and place text at the top of the bars using text() method.To display the figure, use show() method.Examplefrom matplotlib import pyplot as plt import numpy as np plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = ... Read More
1K+ Views
To plot horizontal and vertical lines passing through a point, we can take the following stepsSet the figure size and adjust the padding between and around the subplots.Create two lines using slopes (m1, m2) and intercepts (c1 and c2). Initialize the slopes and intercepts values.Create x data points using numpy.Plot x, m1, m2, c2 and c1 data points using plot() method.Using intercepts and slopes values, find the point of intersection.Plot horizontal and vertical lines with dotted linestyle.Plot xi and yi points on the plotTo display the figure, use show() method.Exampleimport matplotlib.pyplot as plt import numpy as np plt.rcParams["figure.figsize"] = [7.50, ... Read More
325 Views
To plot 3D bars without axes, we can take the following stepsSet the figure size and adjust the padding between and around the subplots.Create a new figure or activate an existing figure using figure() method.Add an axes to the cureent figure as a subplot arrangement.Create x3, y3 and z3 data points using numpy.Create dx, dy and dz data points using numpy.Use bar3d() method to plot 3D bars.To hide the axes, use axis('off') class by name.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 fig = plt.figure() ... Read More
12K+ Views
To plot overlapping lines in matplotlib, we can use variable overlapping that basically sets the opacity or alpha value in the plot.StepsSet the figure size and adjust the padding between and around the subplots.Initialize a variable overlapping to set the alpha value of the line.Plot line1 and line2 with red and green colors, respectively, with the same alpha value.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 overlapping = 0.150 line1 = plt.plot([1, 3, 5, 2, 5, 3, 1], c='red', alpha=overlapping, lw=5) line2 = plt.plot([7, 2, 5, 7, 5, 2, ... Read More
3K+ Views
To disable the minor ticks of a log plot in matplotlib, we can use minorticks_off() method.StepsSet the figure size and adjust the padding between and around the subplots.Create x and y data points using numpy.Add a subplot to the current figure, at index 1.Plot x and y data points with color=red.Make x-scale as log class by name.Set the title of the current plot.Add a subplot to the current figure, at index 2.Plot x and y data points with color=green.Make x-scale as log class by name.Turn off the minor ticks of the plot.Set the title of the plot as index 2.To ... Read More
1K+ Views
To give a border to a line in matplotlib plot function, we can call plot() function twice with varying line width.StepsSet the figure size and adjust the padding between and around the subplots.Create x and y data points using numpy.Plot x and y data points where line width=10 and color=black.Again plot x and y points where line width=8 and color=red.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 x = np.linspace(-2, 2, 100) y = np.sin(x) plt.plot(x, y, c='black', lw=10) plt.plot(x, y, c='red', lw=8) plt.show()OutputRead More
1K+ Views
We can use annotate() to place an emoji at the top of a bar.StepsSet the figure size and adjust the padding between and around the subplots.Make a list of frequencies and labels conatining emojis.Create a new figure or activate an existing figure using figure() method.Plot bars using bar() method.Use annotate() method to place emojis as a labelTo 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 freqs = [7, 8, 5, 3, 6] labels = ['😊', '😲', '😂', '😃', '😛'] plt.figure() p1 = plt.bar(np.arange(len(labels)), freqs) for rect1, ... Read More
5K+ Views
To plot scatter points on a 3D projection with varying marker size, we can take the following stepsSet the figure size and adjust the padding between and around the subplots.Create xs, ys and zs data points using numpyInitialize a variable 's' for varying size of marker.Create a figure or activate an existing figure using figure() method.Add an axes to the current figure as a subplot arrangement using subplots() method.Plot the xs, ys, and zs data points using scatter() method.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"] = ... Read More
1K+ Views
To create a legend for a 3D bar in matplotlib, we can plot 3D bars and place a legend using legend() method.StepsSet the figure size and adjust the padding between and around the subplots.Create a new figure or activate an esxisting figure using figure() method.Add an axes to the figure as part of a subplot arrangement.Create a list of data x3, y3, z3, dx, dy and dz using numpy.Plot a 3D bar using bar3d() method.Create a rectangle axis for legend placement.Use legend() method to place the legend for bars.To display the figure, use show() method.Exampleimport numpy as np from matplotlib ... Read More