Articles on Trending Technologies

Technical articles with clear explanations and examples

Explain the use of SELECT DISTINCT statement in MySQL using Python?

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

Inside SQL tables, columns usually contain duplicate values. We may sometimes need to get only the distinct or different values present in a column in our table since the duplicate values makes it difficult for us to analyze the results returned by the query.Example:Suppose, we have a table named Customers which conatins details about our customers, their names, age and country etc. We need to know to which different countries do our customers belong. We may have 10 customers from India, 15 from America and so on. If we simply select the country column, this will return us the whole ...

Read More

How to plot scatter masked points and add a line demarking masked regions in Matplotlib?

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

To plot scattered masked points and add a line to demark the masked regions, we can take the following steps.StepsSet the figure size and adjust the padding between and around the subplots.Create N, r0, x, y, area, c, r, area1and area2 data points using numpy.Plot x and y data points using scatter() method.To demark the maked regions, plot the curve using plot() method.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 = 100 r0 = 0.6 x = 0.9 * np.random.rand(N) y = 0.9 * ...

Read More

How to move labels from bottom to top without adding "ticks" in Matplotlib?

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

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

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 734 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
Showing 30851–30860 of 61,248 articles
Advertisements