Articles on Trending Technologies

Technical articles with clear explanations and examples

How to plot masked and NaN values in Matplotlib?

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 10-Jun-2021 4K+ Views

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

How to Zoom with Axes3D in Matplotlib?

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 10-Jun-2021 2K+ Views

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

How to get alternating colours in a dashed line using Matplotlib?

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 10-Jun-2021 735 Views

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()Output

Read More

Capacitors in AC Circuits

Manish Kumar Saini
Manish Kumar Saini
Updated on 10-Jun-2021 2K+ Views

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

What is the fetchone() method? Explain its use in MySQL Python?

Pawandeep Kaur
Pawandeep Kaur
Updated on 10-Jun-2021 9K+ Views

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

How to plot a layered image in Matplotlib in Python?

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 10-Jun-2021 1K+ Views

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

How to save a plot in Seaborn with Python (Matplotlib)?

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 10-Jun-2021 4K+ Views

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

How to remove grid lines from an image in Python Matplotlib?

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 10-Jun-2021 7K+ Views

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()Output

Read More

Analog & Digital Multimeter

Manish Kumar Saini
Manish Kumar Saini
Updated on 10-Jun-2021 24K+ Views

MultimeterAs the name implies, a multimeter is device that can be used to measure multiple quantities, i.e., when a single device is used to measure multiple quantities, the device is called multimeter. On the basis of output representation, there are two types of multimeters −Analog multimeterDigital multimeterAnalog MultimeterAn analog multimeter is a permanent magnet moving coil (PMMC) meter type measuring instrument. It works on the principle of d’Arsonval galvanometer. The analog multimeter has an analog display that uses the deflection of a pointer on the scale to indicate the level of measurement being made. The pointer deflects from its initial ...

Read More

How to customize X-axis ticks in Matplotlib?

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 10-Jun-2021 4K+ Views

To customize X-axis ticks in Matplotlib, we can change the ticks length and width.StepsSet the figure size and adjust the padding between and around the subplots.Create lists for height, bars and y_pos data points.Make a bar plot using bar() method.To customize X-axis ticks, we can use tick_params() method, with color=red, direction=outward, length=7, and width=2.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 height = [3, 12, 5, 18, 45] bars = ('A', 'B', 'C', 'D', 'E') y_pos = np.arange(len(bars)) plt.bar(y_pos, height, color='yellow') plt.tick_params(axis='x', colors='red', direction='out', ...

Read More
Showing 41511–41520 of 61,248 articles
Advertisements