
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 33676 Articles for Programming

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 and y (Step 2).Create a pseudocolor plot with a non-regular rectangular grid using pcolormesh() method.To display the figure, use show() method.Examplefrom matplotlib import pyplot as plt, cm, colors import numpy as np plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True side = np.linspace(-2, 2, 15) X, Y = np.meshgrid(side, side) Z = ... Read More

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 minor grid lines.To display the figure, use show() method.Exampleimport seaborn as sns from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True x = [5, 6, 7, 2, 3, 4, 1, 8, 2] ax = sns.histplot(x, kde=True, color='red') ax.grid(b=True, which='major', color='black', linewidth=0.075) ax.grid(b=True, which='minor', color='black', linewidth=0.075) plt.show()OutputRead More

1K+ Views
To annotate the point on a scatter plot with automatically placed arrows, we can take the following steps −Create points for x and y using numpy.Create labels using xpoints.Use scatter() method to scatter the points.Iterate labels, xpoints and ypoints and annotate plot with label, x and y with different properties.To display the figure, use show() method.Exampleimport numpy as np from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True xpoints = np.linspace(1, 10, 25) ypoints = np.random.rand(25) labels = ["%.2f" % i for i in xpoints] plt.scatter(xpoints, ypoints, c=xpoints) for label, x, y in zip(labels, xpoints, ypoints): plt.annotate( ... Read More

2K+ Views
To set a relative frequency in a matplotlib histogram, we can take the following steps −Create a list of numbers for data and bins.Compute the histogram of a set of data, using histogram() method.Get the hist and edges from the histogram.Find the frequency of the histogram.Make a bar with bins (step 1) and freq data (step 4).To display the figure, use show() method.Exampleimport numpy as np from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True a = [-0.125, .15, 8.75, 72.5, -44.245, 88.45] bins = np.arange(-180, 181, 20) hist, edges = np.histogram(a, bins) freq = hist/float(hist.sum()) plt.bar(bins[:-1], ... Read More

14K+ Views
To plot a circle in matplotlib, we can take the following steps −Create a new figure or activate an existing figure using figure() method.Add a subplot arrangement to the current axis.Create a true circle at a center using Circle class.Add a patch to the current axis.Set limits of the x and y axes.To display the figure, use show() method.Examplefrom matplotlib import pyplot as plt, patches plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True fig = plt.figure() ax = fig.add_subplot() circle1 = patches.Circle((0.2, 0.2), radius=0.5, color='green') ax.add_patch(circle1) ax.axis('equal') plt.show()OutputRead More

2K+ Views
To add apha to an existing matplotlib colormap, we can take the following steps −Create data with a 4×4 dimension array using numpy.Get the colormap using plt.cm.RdBU.Create a new colormap using numpy.Set alpha value to the new colormap.Generate a colormap object using the list of colors.Create a new figure or activate an existing figure using figure() method.Add a subplot to the current figure, nrows=1, ncols=2 at index=1.Create a pseudocolor plot with a non-regular rectangular grid using pcolormesh() method.Create a colorbar for scalar mappable instance.Repeat steps 7 to 9, at index 2.Use tight_layout() to adjust the padding between and around the subplots.To ... Read More

1K+ Views
To annotate a heatmap with text in matplotlib, we can take the following steps −Create random data with 4×4 dimension array.Create a pseudocolor plot with a non-regular rectangular grid, using pcolor() method.To put text in the pixels, we can use text() method.To display the figure, use show() method.Exampleimport matplotlib.pyplot as plt import numpy as np plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True data = np.random.rand(4, 4) heatmap = plt.pcolor(data, cmap="PuBuGn_r") for y in range(data.shape[0]): for x in range(data.shape[1]): plt.text(x + 0.5, y + 0.5, '%.4f' % data[y, x], horizontalalignment='center', ... Read More

2K+ Views
To make superscript or subscript text in matplotlib, use LaTeX representation.StepsCreate x and y data points using numpy.Plot x and y data point using plot() method.Put the title with LateX representation using title() method.Use xlabel and ylabel methods to set the label of the axes.Exampleimport numpy as np from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True x = np.linspace(-2, 2, 10) y = 2**x plt.plot(x, y) plt.title('$Y=2^{X}$') plt.xlabel('$X_{data}$') plt.ylabel('$Y_{data}$') plt.show()Output

1K+ Views
To change the spacing of dashes in a dashed line in matplotlib, we can take the following steps −Create data points x and y using numpy.Initialize two variables space and dash_len with value 3.Plot x and y using plot() method, with line style '--', dashes tuple stores the property of dashed line.To display the figure, use show() method.Exampleimport numpy as np from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True x = np.linspace(-1, 1, 100) y = np.sin(x) space = 3 dash_len = 3 plt.plot(x, y, c='red', linestyle='--', dashes=(dash_len, space), lw=5) plt.show()OutputRead More

5K+ Views
To set the ticks on a fixed position 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 on the axes.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 fig, ax = plt.subplots() xtick_loc = [0.20, 0.75, 0.30] ytick_loc = [0.12, 0.80, 0.76] ax.set_xticks(xtick_loc) ax.set_yticks(ytick_loc) plt.show()Output