To move labels from bottom to top without adding ticks, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create random data of 5☓5 dimension matrix.Display the data as an image, i.e., on a 2D regular raster using imshow() method.Use tick_params() method to move labels from bottom to top.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) plt.imshow(data, cmap="copper") plt.tick_params(axis='both', which='major', labelsize=10, labelbottom=False, ... Read More
To plot masked and NaN values in Matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create x and y data points using numpy.Get x2 and y2 data points such that y > 0.7.Get masked y3 data points such that y > 0.7.Mask y3 with NaN values.Plot x, y, y2, y3 and y4 using plot() method.Place a legend to the plot.Set the title of the plot.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 x = ... Read More
To zoom with Axes3D, 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 using figure() method.Get 3D axes object using Axes3D(fig) method.Plot x, y and z data points using scatter() method.To display the figure, use show() method.Examplefrom mpl_toolkits.mplot3d import Axes3D from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True fig = plt.figure() ax = Axes3D(fig) x = [2, 4, 6, 3, 1] y = [1, 6, 8, 1, 3] z = [3, 4, 10, 3, 1] ... Read More
To get alternating colors in a dashed line using Matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplotsGet the current axis.Create x and y data points using numpy.Plot x and y data points with "-" and "--" linestyle.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 ax = plt.gca() x = np.linspace(-10, 10, 100) y = np.sin(x) ax.plot(x, y, '-', color='red', linewidth=5) ax.plot(x, y, '--', color='yellow', linewidth=5) plt.show()OutputRead More
Consider the circuit consisting of a capacitor (C) only. When an alternating voltage is applied across the capacitor, the capacitor being charged in one direction and then in the other as the voltage reverses. Due to the application of alternating voltage across the capacitor the electrons move to and fro around the circuit, thus constituting alternating current.Let the equation of the applied alternating voltage is$$\mathrm{u= V_{m} sin(\omega t)}\:\:\:….. (1)$$As a result of the alternating voltage (v), alternating current will flow through the circuit (i). Let at any instant q is the charge on plates of the capacitor. Thus, $$\mathrm{q=C u ... Read More
Fetchone() methodFetchone() method is used when you want to select only the first row from the table. This method only returns the first row from the MySQL table.Use of fetchone() methodThe fetchone() is not used as a query to be used to the cursor object. The query passed is “SELECT *” which fetches all the rows from the table.Later , we operate fetchone() method on the result returned by “SELECT *”. The fetchone() method then fetches the first row from that result.Steps you need to follow to fetch first row from a table using MySQL in pythonimport MySQL connectorestablish connection ... Read More
To plot a layered image in Matplotlib in Python, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create dx, dy, x, y and extent data using numpy.Create a new figure or activate an existing figure using figure() method.Create data1 and data2 to display the data as an image, i.e., on a 2D regular raster.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 dx, dy = 0.05, 0.05 x = np.arange(-3.0, 3.0, dx) y = np.arange(-3.0, 3.0, ... Read More
To save a plot in Seaborn, we can use the savefig() method.StepsSet the figure size and adjust the padding between and around the subplots.Make a two-dimensional, size-mutable, potentially heterogeneous tabular data.Plot pairwise relationships in a dataset.Save the plot into a file using savefig() method.To display the figure, use show() method.Exampleimport seaborn as sns import pandas as pd import numpy as np import matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True df = pd.DataFrame(np.random.random((5, 5)), columns=["a", "b", "c", "d", "e"]) sns_pp = sns.pairplot(df) sns_pp.savefig("sns-heatmap.png")OutputWhen we execute the code, it will create the following plot and save it ... Read More
To remove grid lines from an image, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Load an image from a file.Convert the image from one color space to another.To remove grid lines, use ax.grid(False).Display the data as an image, i.e., on a 2D regular raster.To display the figure, use show() method.Examplefrom matplotlib import pyplot as plt import cv2 plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True img = cv2.imread('bird.jpg') img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) plt.grid(False) plt.imshow(img) plt.show()OutputRead More
To customize the X-axis label, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Initialize a variable, N, to get the number of sample data.Create x and y data points using numpyPlot x and y data points using plot() method.Customize the X-axis labels with fontweight, color, fontsize, and alignment.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 N = 100 x = np.random.rand(N) y = np.random.rand(N) plt.plot(x, y, 'r*') plt.xlabel('X-axis Label', fontweight='bold', color='orange', ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP