Found 784 Articles for Data Visualization

Setting the display range suplot of errorbars in matplotlib

Rishikesh Kumar Rishi
Updated on 03-Aug-2021 12:17:31

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

Adjust the width of box in boxplot in Python Matplotlib

Rishikesh Kumar Rishi
Updated on 03-Aug-2021 12:14:33

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

How to draw a heart with pylab?

Rishikesh Kumar Rishi
Updated on 03-Aug-2021 12:12:27

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

How to save an image with matplotlib.pyplot?

Rishikesh Kumar Rishi
Updated on 03-Aug-2021 12:10:48

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

How to plot an area in a Pandas dataframe in Matplotlib Python?

Rishikesh Kumar Rishi
Updated on 18-Jun-2021 10:49:46

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

How do I show the same Matplotlib figure several times in a single IPython notebook?

Rishikesh Kumar Rishi
Updated on 18-Jun-2021 10:49:02

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

How to plot sine curve on polar axes using Matplotlib?

Rishikesh Kumar Rishi
Updated on 18-Jun-2021 10:48:29

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

How do I find the intersection of two line segments in Matplotlib?

Rishikesh Kumar Rishi
Updated on 18-Jun-2021 10:48:02

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

How to show minor tick labels on a log-scale with Matplotlib?

Rishikesh Kumar Rishi
Updated on 18-Jun-2021 10:47:30

6K+ Views

To show minor tick labels on a log-scale with 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.Plot x and y data points using plot() methodGet the current axis using gca() method.Set the yscale with log class by name.Change the appearance of ticks and tick label using ick_params() method.Set the minor axis formatter with format strings to format the tick.To display the figure, use show() method.Exampleimport numpy as np import matplotlib.pyplot as plt from matplotlib.ticker import FormatStrFormatter plt.rcParams["figure.figsize"] = [7.50, 3.50] ... Read More

How to hide lines in Matplotlib?

Rishikesh Kumar Rishi
Updated on 18-Jun-2021 10:47:07

4K+ Views

To hide lines in Matplotlib, we can use line.remove() method.StepsSet the figure size and adjust the padding between and around the subplots.Create x, y1 and y2 data points using numpy.Make lines, i.e., line1 and line2, using plot() method.To hide the lines, use line.remove() method.Place a legend on the figure at the upper-right location.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 x = np.linspace(-10, 10, 100) y1 = np.sin(x) y2 = np.cos(x) line1, = plt.plot(x, y1, label="Line 1") line2, = plt.plot(x, y2, label="Line 2") ... Read More

Advertisements