- 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
474 Views
To plot histograms against Pandas/Matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Make a potentially hetrogeneous tabular data using Pandas dataframe.Use the dataframe to make a histogram.To display the figure, use show() method.Examplefrom matplotlib import pyplot as plt import pandas as pd plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True df = pd.DataFrame({'a': [1, 1, 1, 1, 3], 'b': [1, 1, 2, 1, 3], 'c': [2, 2, 2, 1, 3], 'd': [2, 1, 2, 1, 3], }) df.hist() plt.show()Output
378 Views
To plot a Box plot overlaid on top of a Swarm plot in Seaborn, 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., two-dimensional, size-mutable, potentially heterogeneous tabular data.Initialize the plotter, swarmplot.To plot the box plot, 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) sns.boxplot(x="Box1", y="Box2", data=data, showcaps=False, ... Read More
94 Views
To set the display range subplot or errorbars in matplotlib, 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.Create a figure and a set of subplots.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 plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True x = np.arange(0.1, 4, 0.5) y = np.exp(-x) fig, ax = plt.subplots() ax.errorbar(x, y, xerr=0.2, yerr=0.4) plt.show()OutputRead More
6K+ Views
To adjust the width of box in boxplot in Python matplotlib, we can use width in the boxplot() method.StepsSet the figure size and adjust the padding between and around the subplots.Make a Pandas dataframe, i.e., two-dimensional, size-mutable, potentially heterogeneous tabular data.Make a box and whisker plot, using boxplot() method with width tuple to adjust the box in boxplot.To display the figure, use show() method.Exampleimport pandas as pd import numpy as np from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True data = pd.DataFrame({"Box1": np.random.rand(10), "Box2": np.random.rand(10)}) ax = plt.boxplot(data, widths=(0.25, 0.5)) plt.show()OutputRead More
1K+ Views
To draw a heart with pylab/pyplot, we can follow the steps given below −StepsSet the figure size and adjust the padding between and around the subplots.Create x, y1 and y2 data points using numpy.Fill the area between (x, y1) and (x, y2) using fill_between() method.Place text on the plot using text() method at (0, -1.0) point.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, 1000) y1 = np.sqrt(1 - (abs(x) - 1) ** 2) y2 = -3 * np.sqrt(1 - ... Read More
5K+ Views
To save an image with matplotlib.pyplot.savefig(), 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.Plot x and y data points using plot() method.To save the figure, use savefig() method.Exampleimport numpy as np import matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True x = np.linspace(-np.pi, np.pi, 100) plt.plot(x, np.sin(x) * x, c='red') plt.savefig("myimage.png")OutputWhen we execute the code, it will save the following image as "myimage.png" in the Project directory.Read More
2K+ Views
To plot an area in a Pandas dataframe in Matplotlib Python, 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.Return the area between the graph plots.To display the figure, use show() method.Exampleimport pandas as pd import numpy as np from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True df = pd.DataFrame(np.random.rand(10, 4), columns=["a", "b", "c", "d"]) df.plot.area() plt.show()Output
751 Views
To show the same Matplotlib figure several times in a single iPython notebook, 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.Plot the data points on that axes.To show the current figure again, use fig.show() method.ExampleIn [1]: %matplotlib auto Using matplotlib backend: Qt5Agg In [2]: import matplotlib.pyplot as plt In [3]: plt.rcParams["figure.figsize"] = [7.50, 3.50] ...: plt.rcParams["figure.autolayout"] = True In [4]: fig, ax = plt.subplots() In [5]: ax.plot([2, 4, 7, 5, 4, 1]) Out[5]: [] In [6]: fig.show()Output
575 Views
To plot the sine curve on polar axes, 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 figure using figure() methodAdd an '~.axes.Axes' to the figure as part of a subplot arrangement.Get x and y data points using numpy.Plot x and y data points using plot() method.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 = plt.figure() ax = fig.add_subplot(projection='polar') x = np.linspace(-5, 5, 100) y = ... Read More
6K+ Views
To find the intersection of two lines segments in Matplotlib and pass the horizontal and vertical lines through that point, we can take the following steps −Set 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 intercept values.Create x data points using numpy.Plot x, m1, m2, c2 and c1 data points using plot() method.Using intercepts and slope values, find the point of intersection.Plot the horizontal and vertical lines with dotted linestyle.Plot xi and yi points on the plot.To display the figure, use ... Read More