
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

332 Views
To add third level of ticks in Python Matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create t and s data points using numpy.Create a figure and a set of subplots.Plot t and s using plot() method.Create a twin Axes sharing the Y-axis.Plot t and s using plot() method, on axis one.Set X-axis tick position.Create majors, minors and third level of ticks value (thirds).Set major and minor ticks locator with majors, minors and third tick values (thirds)Set ticks length using tick_params().Plot a horizontal line with gray color.To display the ... Read More

653 Views
To plot hysteresis threshold 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.Load some greek coins, Greek coins from Pompeii.Find, high, low, and edges of the images using the sobel filter.Apply hysteresis thresholding to "image".Display the data as an image, i.e., on a 2D regular raster, using imshow() method.Set the titles for the original image and the image with hysteresis threshold.To display the figure, use show() method.Exampleimport matplotlib.pyplot as plt from skimage import data, filters plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] ... Read More

2K+ Views
To make semilogx and semilogy 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.Scatter and plot x and y data points.Make a plot with log scaling on the X axis.Make a plot with log scaling on the Y 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 x = [10, 100, 1000, 10000, 100000] y = [2, 4, 8, 16, 32] fig = plt.figure() plt.scatter(x, y) plt.plot(x, y) ... Read More

744 Views
To programmatically stop interaction for specific figures in Jupyter notebook, we can use plt.off() to stop any interaction after that.Execute the following commnads sequentially −%matplotlib autoimport matplotlib.pyplot as pltplt.rcParams["figure.figsize"] = [7.50, 3.50]plt.rcParams["figure.autolayout"] = TrueCreate a figure and a set of subplots.Plot the line on the axis (From step 5).Turn off the interaction.To display the figure, use show() method.ExampleIn [1]: %matplotlib auto Using matplotlib backend: Qt5Agg In [2]: import matplotlib.pyplot as plt In [3]: plt.rcParams["figure.figsize"] = [7.50, 3.50] ...: plt.rcParams["figure.autolayout"] = True In [4]: fig, ax = plt.subplots() In [5]: ax.plot([2, 4, 7, 5, 4, 1]) ... Read More

2K+ Views
To animate 3D plot_surface in Matplotlib, we can take the following steps−Initialize variables for number of mesh grids (N), frequency per second (fps) to call a function, and frame numbers (frn).Create x, y and z array for a curve.Make a function to make a z-array using lambda function.To pass a function into animation class, make a user-defined function that removes the previous plot and plot a surface using x, y and z-array.Create a new figure or activate an existing figure.Add a subplot arrangement using subplots() method.Set the Z-axis limit using set_zlim() method.Call the animation class to animate the surface plot.To ... Read More

2K+ Views
To combine several matplotlib axes subplots into one figure, we can use subplots() method with nrow=2.StepsSet the figure size and adjust the padding between and around the subplots.Create x, y1 and y2 data points using numpy.Create a figure and a set of subplots.Plot x, y1 and y2 data points using plot() 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 x = np.linspace(-10, 10, 100) y1 = np.sin(x) y2 = np.cos(x) fig, axes = plt.subplots(nrows=2) line1, = axes[0].plot(x, y1, color='red') line2, ... Read More

1K+ Views
To get xkcd font working, we can use plt.xkcd() to turn on sketch-style drawing mode.StepsSet the figure size and adjust the padding between and around the subplots.Create x and y data points using numpy.Use plt.xkcd() to turn on sketch-style drawing mode.Create a new figure or activate an existing figure.Add an axis to the figure as part of a subplot arrangement.Plot x and y data points using plot() method.Place a text and title on the plot.To display the figure, use show() method.Examplefrom matplotlib import pyplot as plt import numpy as np plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True x ... Read More

2K+ Views
To make colorbar orientation horizontal in Python, we can use orientation="horizontal" in the argument.StepsSet the figure size and adjust the padding between and around the subplots.Create random x, y and z data points using numpy.Create a figure and a set of subplots.Use scatter() method to plot x, y and z data points.Create a colorbar for a ScalarMappable instance, with horizontal orientation.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, y, z = np.random.rand(3, 50) f, ax = plt.subplots() points = ax.scatter(x, y, c=z, s=50, ... Read More

17K+ Views
To show points coordinate in a plot in Python, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create lists of x and y data points.Plot x and y data points with red color and starred markerSet some axis properties.Iterate x and y to show the coordinates on the plot.Exampleimport matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True x = [3, 1, 2, 5] y = [5, 2, 4, 7] plt.plot(x, y, 'r*') plt.axis([0, 6, 0, 20]) for i, j in zip(x, y): plt.text(i, ... Read More

59K+ Views
To plot an array in Python, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create two arrays, x and y, using numpy.Set the title of the curve using title() method.Plot x and y data points, with red color.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.array([5, 4, 1, 4, 5]) y = np.sort(x) plt.title("Line graph") plt.plot(x, y, color="red") plt.show()Output