
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 10476 Articles for Python

1K+ Views
To plot a 3D patch collection in 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.Get the current axes and set projection as 3d.Iterate ["x", "y", "z"] list, and set the circle patch using pathpatch_2d_to_3d() method to convert a PathPatch to a PathPatch3D object.To display the figure, use show() method.Exampleimport matplotlib.pyplot as plt from matplotlib.patches import Circle import mpl_toolkits.mplot3d.art3d as art3d plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True fig = plt.figure() ax = fig.gca(projection='3d') for i in ["x", ... Read More

4K+ Views
To fill the area under a curve in a Seaborn distribution plot, we can use distplot() and fill_between() methods.StepsSet the figure size and adjust the padding between and around the subplots.Create a list of data points.Plot a univariate distribution of observations.To fill the area under the curve, use fill_between() method.Set or retrieve autoscaling margins, x=0 and y=0.To display the figure, use show() method.Exampleimport seaborn as sns import scipy.stats as stats import matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True x = [2.0, 7.5, 9.0, 8.5] ax = sns.distplot(x, fit_kws={"color": "red"}, kde=False, fit=stats.gamma, hist=None, label="label 1") l1 = ... Read More

2K+ Views
To adjust tick frequency for X-axis, we can take 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 points.Create x and y data points using numpy.Plot x and y data points using plot() method.Initialize a variable freq_x to adjust the frequency of the xticks.Use xticks() method to set the xticks.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 N = 10 x = np.random.randint(low=0, high=N, size=N) y = np.random.randint(low=0, high=N, ... Read More

998 Views
To save scatterplot animations with matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Initialize four variables, steps, nodes, positions and solutions.Append positions and solutions values in the list.Create a figure and a set of subplots.Initialize a variable for marker size.Configure the grid lines.Make an animation by repeatedly calling a function *animate*, to clear the axis, add new axis sublot, and plot scatter points on the axis.Save the animated scatter plot as a .gif file.Exampleimport matplotlib.pyplot as plt import matplotlib.animation as animation import numpy as np plt.rcParams["figure.figsize"] = [7.50, ... Read More

249 Views
To plot a line (polygonal chain) with matplotlib with minimal smoothing, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Initalize a variable, N, to get the number of data points.Create x and y data points using numpy.Get 1-D monotonic cubic interpolation, using pchip() method.Plot (x, interp(x)) and (x, y) data points using numpy.To display the figure, use show() method.Exampleimport numpy as np from scipy.interpolate import pchip import matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True N = 50 x = np.linspace(-10, 10, N) y = np.sin(x) ... Read More

568 Views
To check if points are inside ellipse faster than contains_point method, 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.Set the aspect ratios, equal.Create x and y data points using numpy.Initialize center, height, width and angle of the ellipse.Get a scale free ellipse.Add a '~.Patch' to the axes' patches; return the patch.If the point lies inside an ellipse, change its color to "red" else "green".Plot x and y data points using scatter() method, with colors.To display the figure, use show() method.Exampleimport matplotlib.pyplot as ... Read More

4K+ Views
To change the color of a single X-axis tick label in 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.Add an '~.axes.Axes' to the figure as part of a subplot arrangement.Create x and y data points using numpy.Plot x and y data points using plot() method.To set the color of X-axis tick label in matplotlib, we can use tick_params() method with axis='x' and color='red'.To display the figure, use show() method.Exampleimport numpy as np from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] ... Read More

2K+ Views
To appropriately plot losses values acquired by (loss_curve_) from MLPCIassifier, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Make a params, a list of dictionaries.Make a list of labels and plot arguments.Create a figure and a set of subplots, with nrows=2 and ncols=Load and return the iris dataset (classification).Get x_digits and y_digits from the dataset.Get customized data_set, list of tuples.Iterate zipped, axes, data_sets and the list of name of titles.In the plot_on_dataset() method; set the title of the current axis.Get the Multi-layer Perceptron classifier instance.Get mlps, i.e a list of ... Read More

299 Views
To use Font Awesome symbol as a marker, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create a list of symbols; has to be plotted.Create x and y data points using numpy.Create a new figure or activate an existing figure using figure() method.Iterate the symbols and use it while plotting a line.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 symbols = [u'\u2B21', u'\u263A', u'\u29C6', u'\u2B14', u'\u2B1A', u'\u25A6', u'\u229E', u'\u22A0', u'\u22A1', u'\u20DF'] x = np.arange(10) ... Read More

5K+ Views
Librosa is a Python package that helps to analyse audio and music files. This package also helps to create music retrieval information systems. In this article, we will see how to save a Librosa spectrogram plot as an image of specific size.StepsSet the figure size and adjust the padding between and around the subplots..Create a figure and a set of subplots.Initialize three different variables, hl, hi, wi, to store samples per time in the spectrogram, height and width of the images.Load a demo track.Create a window, i.e., a list for audio time series..Compute a mel-scaled spectrogram, using melspectrogram() with window ... Read More