Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

1,016 Articles Published

Articles by Rishikesh Kumar Rishi

Page 12 of 102

How to make a quiver plot in polar coordinates using Matplotlib?

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 23-Sep-2021 2K+ Views

To make a quiver plot in polar coordinates using Matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create radii, thetas, theta and r data points using numpy.Create a new figure or activate an existing figure.Add an 'ax' to the figure as part of a subplot arrangement.Make poly collections of arrows.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 radii = np.linspace(0, 1, 5) thetas = np.linspace(0, 2 * np.pi, 20) theta, r = ...

Read More

How to decrease the hatch density in Matplotlib?

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 23-Sep-2021 859 Views

To decrease the hatch density in Matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Make a customized horizontal hatch class to override the density.Append the horizontal hatch class.Create a new figure or activate an existing figure.Add an 'ax1' to the figure as part of a subplot arrangement.Make lists of data points.Make a bar plot with x and ydata points, with hatch='o', color='green' and edgecolor='red'.To display the figure, use show() method.Examplefrom matplotlib import pyplot as plt, hatch plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True class MyHorizontalHatch(hatch.HorizontalHatch):    def ...

Read More

How to give Matplolib imshow plot colorbars a label?

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 23-Sep-2021 5K+ Views

To give matplotlib imshow() plot colorbars a label, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create 5×5 data points using Numpy.Use imshow() method to display the data as an image, i.e., on a 2D regular raster.Create a colorbar for a ScalarMappable instance, im.Set colorbar label using set_label() method.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 data = np.random.rand(5, 5) im = plt.imshow(data, cmap="copper") cbar = plt.colorbar(im) cbar.set_label("Colorbar") plt.show()Output

Read More

How to set a title above each marker which represents a same label in Matplotlib?

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 23-Sep-2021 352 Views

To set a title above each marker which represents the same label in Matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create x data points using Numpy.Create four curves, c1, c2, c3 and c4 using plot() method.Place a legend on the figure, such that the same label marker would come together.To display the figure, use show() method.Exampleimport numpy as np from matplotlib import pyplot as plt, legend_handler plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True x = np.linspace(-10, 10, 100) c1, = plt.plot(x, np.sin(x), ls='dashed', label='y=sin(x)') c2, ...

Read More

How to change the color and add grid lines to a Python Matplotlib surface plot?

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 23-Sep-2021 2K+ Views

To change the color and add grid lines to a Python surface plot, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create x, y and h data points using numpy.Create a new figure or activate an existing figure.Get 3D axes object, with figure (from Step 3).Create a surface plot, with orange color, edgecolors and linewidth.Exampleimport numpy as np import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True x = np.arange(-5, 5, 0.25) y = np.arange(-5, 5, 0.25) x, y = np.meshgrid(x, ...

Read More

How to find the matplotlib style name?

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 23-Sep-2021 232 Views

To find the matplotlib style name, we can take the following steps −import matplotlib.pyplot as pltprint(plt.style.library)Exampleimport matplotlib.pyplot as plt print(plt.style.library)Output{'bmh': RcParams({'axes.edgecolor': '#bcbcbc',    'axes.facecolor': '#eeeeee',    'axes.grid': True,    'axes.labelsize': 'large', 'axes.prop_cycle': cycler('color', ['#348ABD', '#A60628', '#7A68A6',       '#467821', '#D55E00', '#CC79A7', '#56B4E9', '#009E73', '#F0E442', '#0072B2']),    'axes.titlesize': 'x-large',    'grid.color': '#b2b2b2',    'grid.linestyle': '--',    'grid.linewidth': 0.5,    'legend.fancybox': True,    'lines.linewidth': 2.0,    'mathtext.fontset': 'cm',    'patch.antialiased': True,    'patch.edgecolor': '#eeeeee',    'patch.facecolor': 'blue',    'patch.linewidth': 0.5,    'text.hinting_factor': 8,    'xtick.direction': 'in',    'ytick.direction': 'in'}), 'classic': RcParams({'_internal.classic_mode': True,    'agg.path.chunksize': 0, ...

Read More

How to get an interactive plot of a pyplot when using PyCharm?

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 23-Sep-2021 3K+ Views

To get an interactive plot of a pyplot when using PyCharm, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Set the background style.Plot the data on the axes.To display the figure, use show() method.Exampleimport matplotlib as mpl import matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True mpl.use('Qt5Agg') plt.plot(range(10)) plt.show()Output

Read More

How to increase the spacing between subplots in Matplotlib with subplot2grid?

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 23-Sep-2021 9K+ Views

To increase the spacing between subplots with subplot2grid, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Add a grid layout to place subplots within a figure.Update the subplot parameters of the grid.Add a subplot to the current figure.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 ax = plt.GridSpec(2, 2) ax.update(wspace=0.5, hspace=0.5) ax1 = plt.subplot(ax[0, :]) ax2 = plt.subplot(ax[1, 0]) ax3 = plt.subplot(ax[1, 1]) plt.show()Output

Read More

How to get multiple overlapping plots with independent scaling in Matplotlib?

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 23-Sep-2021 3K+ Views

To get multiple overlapping plots with independent scaling in Matplotlib, 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 a list of data points using plot() method on a seperate Y-axis and overlapping X-axis.Create a twin Axes sharing the X-axis.Plot a list of data points using plot() method on a seperate Y-axis and overlapping X-axis.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 fig, ax1 = plt.subplots() ax1.plot([1, 2, 3, 4, 5], color='red') ...

Read More

How to display a sequence of images using Matplotlib?

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 23-Sep-2021 3K+ Views

To display a sequence of images using Matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Make a list of images that have to be drawn.Turn off the axes.Iterate the images and redraw over the axes.Take a pause after each draw.Exampleimport matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True images = ['opera.jpg', 'mountain.jpg', '9.jpg'] plt.axis('off') img = None for f in images:    im = plt.imread(f)    if img is None:       img = plt.imshow(im)       plt.pause(0.5)    else:     ...

Read More
Showing 111–120 of 1,016 articles
« Prev 1 10 11 12 13 14 102 Next »
Advertisements