Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

1,016 Articles Published

Articles by Rishikesh Kumar Rishi

Page 30 of 102

How to create a line chart using Matplotlib?

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 04-Aug-2021 1K+ Views

To create a line chart using matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Make lists of years and population growth.Plot years and population on the line using plot() method.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 years = [1901, 1911, 1921, 1931, 1941, 1951,         1961, 1971, 1981, 1991, 2001, 2011] population = [237.4, 238.4, 252.09, 251.31, 278.98, 318.66, 361.09, 439.23, 548.16, 683.33, 846.42, 1028.74] plt.plot(years, population, color='red', marker='o') plt.show()Output

Read More

How to use different markers for different points in a Pylab scatter plot(Matplotlib)?

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 04-Aug-2021 8K+ Views

To use different markers for different points in a Pylab (Pyplot) scatter plot, we can use the following steps −Set the figure size and adjust the padding between and around the subplots.Initialize a variable, N, for number of sample data.Create x and y random data points.Make a list of markers.Zip the x, y and markers.Iterate the zipper objects and plot the data points with different markers.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 N = 10 x = np.random.rand(N) y = np.random.rand(N) ...

Read More

How to show an image in Matplotlib in different colors with different channels?

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 04-Aug-2021 3K+ Views

To slice an image into Red, Green and Blue channels with misc.imread, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Read an image from a file into an array.Make lists of colormaps and titles.Create a figure and a set of subplots.Zip the axes, images, titles and colormaps.Iterate zipped objs and set the title of each channel image.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 image = plt.imread('bird.png') titles = ['With red channel', 'With green channel', 'With blue channel'] cmaps ...

Read More

How to pixelate a square image to 256 big pixels with Python Matplotlib?

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 04-Aug-2021 394 Views

To pixelate a square image to 256 big pixels with Python, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Open and identify the given image file.Resize the image samples.Make resultant images and resize them.Save the resultant figure.Examplefrom PIL import Image from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True img = Image.open("bird.png") imgSmall = img.resize((16, 16), resample=Image.BILINEAR) result = imgSmall.resize(img.size, Image.NEAREST) result.save('result.png')Input ImageOutput Image

Read More

How to animate a Seaborn heatmap or correlation matrix(Matplotlib)?

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 04-Aug-2021 3K+ Views

To animate a Seaborn heatmap or correlation matrix, 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.Make a dimension tuple.Make a Seaborn heatmap.Create an init() method for the first heatmap.Use FuncAnimation() class to make an animation by repeatedly calling a function animate that will create a random dataset and create a heatmap.To display the figure, use show() method.Exampleimport numpy as np import seaborn as sns import matplotlib.pyplot as plt from matplotlib import animation plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True ...

Read More

How to turn off transparency in Matplotlib's 3D Scatter plot?

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 04-Aug-2021 1K+ Views

To turn off transparency in Matplotlib's 3D scatter plot, we can use depthshade to shade the scatter markers to give the appearance of depth.StepsSet the figure size and adjust the padding between and around the subplots.Create a new figure or activate an existing figure.Add an ax to the figure as part of a subplot arrangement.Create random data points x, y and z using numpy.Use scatter method to plot x, y and z data points on 3D axes with depthshade=False.To display the figure, use show() methpod.Exampleimport numpy as np from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] ...

Read More

How to plot the outline of the outer edges on a Matplotlib line in Python?

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 04-Aug-2021 2K+ Views

To plot the outline of the outer edges on a Matplotlib in Python, 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 with linewidth set to 10 and 5, to get the visible outline edges.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(-10, 10, 100) y = np.sin(x) plt.plot(x, y, lw=10, color='red') plt.plot(x, y, lw=5, color='yellow') plt.show()Output

Read More

How to merge two existing Matplotlib plots into one plot?

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 04-Aug-2021 17K+ Views

To merge two existing matplotlib plots into one plot, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create x, y1 and y2 data points using numpy.Plot (x, y1) and (x, y2) points using plot() method.Get the xy data points of the current axes.Use argsort() to return the indices that would sort an array.Append x and y data points of each plot.Plot X and Y data points at the 2nd index subplot.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"] ...

Read More

How does imshow handle the alpha channel with an M x N x 4 input?(Matplotlib)

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 04-Aug-2021 457 Views

Let's take an example to see how imshow() handles the alpha channel with an M×N×4 input.StepsSet the figure size and adjust the padding between and around the subplots.Return a new array of given shape and type, filled with 1's.Handle the alpha channel.Display the data as an image, i.e., on a 2D regular raster.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 d = np.ones((100, 100, 4), dtype=np.uint8)*255 d[:, :, 1] = np.linspace(0, 255, num=100) plt.imshow(d) plt.show()Output

Read More

How to set a Matplotlib rectangle edge to outside of specified width?

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 04-Aug-2021 621 Views

To set a Matplotlib rectangle edge to outside of specified width, 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.Add an ax to the figure as part of a subplot arrangement.Initialize a variable line_width to set the rectangle outside of specified width. Use the variables xy, w and h for rectangle's center, width and height.Get a rectangle instance, with xy anchor points and its height and width.Get the offset transformbox instance.Add an artist patch, r (Step 5).Get the container for an OffsetBox ...

Read More
Showing 291–300 of 1,016 articles
« Prev 1 28 29 30 31 32 102 Next »
Advertisements