Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

1,016 Articles Published

Articles by Rishikesh Kumar Rishi

Page 52 of 102

Plot a 3D surface from {x,y,z}-scatter data in Python Matplotlib

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 05-Jun-2021 5K+ Views

To plot a 3D surface from x, y and z scatter data in Python, 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() method.Add an axes to the figure as part of a subplot arrangement.Create x, y, X, Y and Z data points using numpy.Plot x, y and z data points using plot_surface() method.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 fig = plt.figure() ...

Read More

How can I get the (x,y) values of a line that is plotted by a contour plot (Matplotlib)?

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 05-Jun-2021 495 Views

To get the (x, y) values of a line that is plotted by a contour plot, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create a 3D contour plot using contour() method.Get the contour plot collections and get the paths.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 m = [[3, 2, 1, 0], [2, 4, 1, 0], [2, 4, 1, 3], [4, 3, 1, 3]] cs = plt.contour([3, 4, 2, 1], [5, 1, 2, 3], m) p1 = cs.collections[0].get_paths() for item in p1:    print(item.vertices) plt.show()Output

Read More

How to animate a time-ordered sequence of Matplotlib plots?

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 05-Jun-2021 779 Views

To animate a time-ordered sequence of Matplotlib plots, 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 axes to the figure as part of a subplot arrangement.Return the first recurrence after the given datetime instance using after() method.Write an animate() method to animate. 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 matplotlib.use('TkAgg') import matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True ...

Read More

Fill the area under a curve in Matplotlib python on log scale

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 05-Jun-2021 707 Views

To fill the area under a curve in Matplotlib python on log scale, 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 y2 data points using plot() method.Fill the area between the two curves.Set the scale of the axes.Place a legend on the plot.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(-1, 1, 100) y1 = np.sin(x) y2 = np.cos(x) ...

Read More

How to force errorbars to render last with Matplotlib?

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 05-Jun-2021 154 Views

To force errorbars to render last with matplotlib, 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() method.Get the current axis using gca() method.Plot the list of linesPlot y versus x as lines and/or markers with attached errorbars.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 fig = plt.figure() ax = plt.gca() [ax.plot(np.random.rand(10)) for j in range(10)] ax.errorbar(range(10), np.random.rand(10), yerr=.3 * np.random.rand(10)) plt.show()Output

Read More

What names can be used in plt.cm.get_cmap?

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 05-Jun-2021 305 Views

Matplotlib provides a number of colormaps, and others can be added using :func:'~matplotlib.cm.register_cmap'. This function documents the built-in colormaps, and will also return a list of all registered colormaps, if called.Examplefrom matplotlib import pyplot as plt cmaps = plt.colormaps() print("Possible color maps are: ") for item in cmaps:    print(item)OutputAccent Accent_r Blues ... ... ... viridis_r winter winter_r

Read More

Plot multiple time-series DataFrames into a single plot using Pandas (Matplotlib)

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 05-Jun-2021 2K+ Views

To plot multiple time-series data frames into a single plot using Pandas, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create a Pandas data frame with time series.Set the time series index for plot.Plot rupees and dollor on the plot.To display the figure, use show() method.Exampleimport numpy as np import pandas as pd from matplotlib import pyplot as plt, dates plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True df = pd.DataFrame(dict(date=list(pd.date_range("2021-01-01", periods=10)), rupees=np.linspace(1, 10, 10), dollar=np.linspace(10, 20, 10))) df.set_index(pd.to_datetime(df.date), drop=True).plot() df = df.set_index(pd.to_datetime(df.date), drop=True) df.rupees.plot(grid=True, label="rupees", legend=True) df.dollar.plot(secondary_y=True, ...

Read More

How to make several legend keys to the same entry in Matplotlib?

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 05-Jun-2021 1K+ Views

To make several legend keys to the same entry in Matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Plot line1 and line2 using plot() method.Use legend() method to place a legend over the plot with numpoints=1To display the figure, use show() method.Exampleimport matplotlib.pyplot as plt from matplotlib.legend_handler import HandlerTuple plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True p1, = plt.plot([1, 2.5, 3], 'r-d') p2, = plt.plot([3, 2, 1], 'k-o') l = plt.legend([(p1, p2)], ['Two keys'], numpoints=1, handler_map={tuple: andlerTuple(ndivide=None)}) plt.show()Output

Read More

Removing Horizontal Lines in image (OpenCV, Python, Matplotlib)

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 05-Jun-2021 4K+ Views

To remove horizontal lines in an image, we can take the following steps −Read a local image.Convert the image from one color space to another.Apply a fixed-level threshold to each array element.Get a structuring element of the specified size and shape for morphological operations.Perform advanced morphological transformations.Find contours in a binary image.Repeat step 4 with different kernel size.Repeat step 5 with a new kernel from step 7.Show the resultant image.Exampleimport cv2 image = cv2.imread('input_image.png') cv2.imshow('source_image', image) gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) thresh = cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY_INV + cv2.THRESH_OTSU)[1] horizontal_kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (25, 1)) detected_lines = cv2.morphologyEx(thresh, cv2.MORPH_OPEN, ...

Read More

Specifying the line width of the legend frame in Matplotlib

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 05-Jun-2021 4K+ Views

To specify the line width of the legend frame in Matplotlib, we can use set_linewidth() method.StepsSet 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 using subplots() method.Plot x and y using plot() method.Place a legend on the figure and get the legend instance.Get the lines and set the line width in the legend frame.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(-5, 5, 100) y ...

Read More
Showing 511–520 of 1,016 articles
« Prev 1 50 51 52 53 54 102 Next »
Advertisements