Label a Patch in Matplotlib

Rishikesh Kumar Rishi
Updated on 10-Aug-2021 07:01:05

3K+ Views

To label a patch in matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Initialize the center of the rectangle patch.Create a new figure or activate an existing figure.Add an 'ax' to the figure as part of a subplot arrangement.Add a 'rectangle' to the axes' patches; return the patch.Place a legend on the figure.To display the figure, use show() method.Exampleimport matplotlib.pyplot as plt import matplotlib.patches as patches plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True x = y = 0.1 fig = plt.figure() ax = fig.add_subplot(111) patch = ... Read More

Sort Bars in a Bar Plot in Ascending Order Using Matplotlib

Rishikesh Kumar Rishi
Updated on 10-Aug-2021 06:58:34

15K+ Views

To sort bars in a bar plot in ascending order, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Make a list of data for bar plots.Create a bar plot using bar() method, with sorted data.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 data = [3, 5, 9, 15, 12] plt.bar(range(len(data)), sorted(data), color='red', alpha=0.5) plt.show()Output

Add Titles to Legend Rows in Matplotlib

Rishikesh Kumar Rishi
Updated on 10-Aug-2021 06:52:57

2K+ Views

To add titles to the legend rows in 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 lists of markers and labels.Create a figure and a set of subplots.Plot the lines using plot() method, with different labels and markers.Get the plot handlers for half of the plot.Get the labels for the legends.Place the legends on the plot.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.exp(-np.arange(5)) markers ... Read More

Difference Between Importing Matplotlib and Matplotlib Pyplot

Rishikesh Kumar Rishi
Updated on 10-Aug-2021 06:51:02

2K+ Views

When we import matplotlib, we are importing all its libraries, whereas importing matplotlib.pyplot only imports pyplot's properties.stepsImport matplotlib.pyplot as pltSet 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 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.random.rand(10) y = np.random.rand(10) plt.plot(x, y) plt.show()Output

Plotting a Heatmap for 3 Columns in Python with Seaborn

Rishikesh Kumar Rishi
Updated on 10-Aug-2021 06:49:00

2K+ Views

To plot a heatmap for 3 columns in Python with Seaborn, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create a dataframe, df, with 3 columns.Plot the rectangular data as a color-encoded matrix.To display the figure, use show() method.Exampleimport seaborn as sns import pandas as pd import numpy as np import matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True df = pd.DataFrame(np.random.random((3, 3)), columns=["a", "b", "c"]) sns.heatmap(df, cbar=False) plt.show()Output

Plot Two Histograms Side by Side Using Matplotlib

Rishikesh Kumar Rishi
Updated on 10-Aug-2021 06:45:16

14K+ Views

To plot two histograms side by side using matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Make two dataframes, df1 and df2, of two-dimensional, size-mutable, potentially heterogeneous tabular data.Create a figure and a set of subplots.Make a histogram of the DataFrame's, df1 and df2.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 df1 = pd.DataFrame(dict(a=[1, 1, 1, 1, 3])) df2 = pd.DataFrame(dict(b=[1, 1, 2, 1, 3])) fig, axes = plt.subplots(1, 2) ... Read More

Make a Circular Contour Plot using Matplotlib Pyplot

Rishikesh Kumar Rishi
Updated on 10-Aug-2021 06:43:03

821 Views

To make a circular matplotlib.pyplot.contourf, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create x, y, a, b and c data points using Numpy.Create a figure and a set of subplots.Make a Contour plot using contourf() method.Set the aspect ratios.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.linspace(-0.5, 0.5, 100) y = np.linspace(-0.5, 0.5, 100) a, b = np.meshgrid(x, y) c = a ** 2 + b ** 2 - 0.2 ... Read More

Set Background Color of a Column in a Matplotlib Table

Rishikesh Kumar Rishi
Updated on 10-Aug-2021 06:40:23

2K+ Views

To set the background color of a column in a matplotlib table, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Make a tuple for columns attribute.Make a list of lists, i.e., list of records.Make a list of lists, i.e., color of each cell.Create a figure and a set of subplots.Add a table to an axes, ax.Turn off the axes.To display the figure, use show() method.Exampleimport matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True columns = ('name', 'age', 'marks', 'salary') cell_text = [["John", "23", "98", "234"], ... Read More

Get Affine Transformation Matrix in PHP using imageaffinematrixget

Urmila Samariya
Updated on 09-Aug-2021 13:59:29

197 Views

imageaffinematrixget() is an inbuilt function in PHP that is used to get an affine transformation matrix. This function is often used in linear algebra and computer graphics.Syntaxarray imageaffinematrixget(int $type, mixed $options)Parametersimageaffinematrixget() accepts only two parameters: $type and $options.$type − The $type parameter specifies the integer to IMG_AFFINE constants.IMG_AFFINE_TRANSLATEIMG_AFFINE_SCALEIMG_AFFINE_ROTATEIMG_AFFINE_SHEAR_HORIZONTALIMG_AFFINE_SHEAR_VERTICAL$options − If type is IMG_AFFINE_TRANSLATE or IMG_AFFINE_SCALE, options has to be an array with keys x and y, both having float values. If type is IMG_AFFINE_ROTATE, IMG_AFFINE_SHEAR_HORIZONTAL or IMG_AFFINE_SHEAR_VERTICAL, options has to be a float specifying the angle.Return ValuesIt returns an affine transformation matrix, an array with keys from 0 to 5 ... Read More

Check Anti-Alias Functions Using imageantialias in PHP

Urmila Samariya
Updated on 09-Aug-2021 13:56:12

149 Views

imageantialias() is an inbuilt function in PHP that is used to check whether antialias function is used or not. It activates the fast drawing anti-aliased methods for lines and wired polygons. It works only with true-color images and it doesn't support alpha components.Syntaxbool imageantialias($image, $enabled)Parametersimageantialias() takes two parameters: $image and $enabled.$image − The $image parameter is a GdImage object and an image resource that is returned by the image creation function imagecreatetruecolor.$enabled − The $enabled parameter is used to check whether antialiasing is enabled or notReturn Valuesimageantialias() returns True on success and False on failure.Example 1OutputRead More

Advertisements