Rishikesh Kumar Rishi has Published 1162 Articles

Setting Transparency Based on Pixel Values in Matplotlib

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 08-May-2021 09:07:03

877 Views

To set transparency based on pixel values in matplotlib, get masked data wherever data is less than certain values. Lesser value will result in full overlapping between two images.StepsCreate data1 and data2 using numpy.Get the masked data using numpy's masked_where() method.Using subplots() method, create a figure and a set of subplots (fig and ax).Display the ... Read More

How can I change the font size of ticks of axes object in Matplotlib?

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 08-May-2021 09:06:39

492 Views

To change the font size of ticks of axes object in matplotlib, we can take the following steps −Create x and y data points using numpy.Using subplots() method, create a figure and a set of subplots (fig and ax).Plot x and y data points using plot() method, with color=red and linewidth=5.Set ... Read More

Show decimal places and scientific notation on the axis of a Matplotlib plot

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 08-May-2021 09:06:19

6K+ Views

To show decimal places and scientific notation on the axis of a matplotlib, we can use scalar formatter by overriding _set_format() method.StepsCreate x and y data points using numpy.Plot x and y using plot() method.Using gca() method, get the current axis.Instantiate the format tick values as a number class, i.e., ScalarFormatter.Set size thresholds ... Read More

How to plot vectors in Python using Matplotlib?

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 08-May-2021 08:56:54

7K+ Views

To plot vectors in Python using matplotlib, we can take the following steps −Create a matrix of 2×3 dimension.Create an origin point, from where vecors could be originated.Plot a 3D fields of arrows using quiver() method with origin, data, colors and scale=15.Exampleimport numpy as np from matplotlib import pyplot as plt ... Read More

How to rotate the rectangle patch in a plot using Matplotlib?

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 08-May-2021 08:56:26

2K+ Views

To rotate the rectangle patch in a plot, we can use angle in the Rectangle() class to rotate it.StepsCreate a figure and a set of subplots using subplots() method.Add a rectangle on the patch, angle=45°.Add a patch on the axis.To display the figure, use show() method.Examplefrom matplotlib import pyplot as plt, patches ... Read More

How to change the spacing between ticks in Matplotlib?

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 08-May-2021 08:56:03

7K+ Views

To set ticks on a fixed position or change the spacing between ticks in matplotlib, we can take the following steps −Create a figure and add a set of subplots.To set the ticks on a fixed position, create two lists with some values.Use set_yticks and set_xticks methods to set the ticks ... Read More

How to normalize a histogram in Python?

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 08-May-2021 08:55:40

14K+ Views

To normalize a histogram in Python, we can use hist() method. In normalized bar, the area underneath the plot should be 1.StepsMake a list of numbers.Plot a histogram with density=True.To display the figure, use show() method.Exampleimport matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True k = [5, ... Read More

How to set a default colormap in Matplotlib?

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 08-May-2021 08:55:19

4K+ Views

To set a default colormap in matplotlib, we can take the following steps −Create random data using numpy, array dimension 4×4.Create two axes and one figure using subplots() method.Display the data as an image with the default colormap.Set the title of the image, for the default colormap.Set the default colormap using ... Read More

How to plot a 3D density map in Python with Matplotlib?

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 08-May-2021 08:54:49

2K+ Views

To plot a 3D density map in Python with matplotlib, we can take the following steps −Create side, x, y and z using numpy. Numpy linspace helps to create data between two points based on a third number.Return the coordinate matrices from coordinate vectors using side data.Create exponential data using x ... Read More

Add minor gridlines to Matplotlib plot using Seaborn

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 08-May-2021 08:54:25

3K+ Views

To add minor gridlines to matplotlib plot using Seaborn, we can take the following steps −Create a list of numbers to plot a histogram using Seaborn.Plot univariate or bivariate histograms to show distributions of datasets using histplot() method.To make minor grid lines, we can first use major grid lines and then ... Read More

Advertisements