Using plt.rcParams["figure.figsize"], we can get the width setting.StepsTo get the plot width setting, use plt.rcParams["figure.figsize"] statement.Override the plt.rcParams["figure.figsize"] with a tuple (12, 9).After updating the width, get the updated width using plt.rcParams["figure.figsize"].ExamplesIn IDEExampleimport matplotlib.pyplot as plt print("Before, plot width setting:", plt.rcParams["figure.figsize"]) plt.rcParams["figure.figsize"] = (12, 9) print("Before, plot width setting:", plt.rcParams["figure.figsize"])OutputBefore, plot width setting: [6.4, 4.8] Before, plot width setting: [12.0, 9.0]In IPythonExampleIn [1]: from matplotlib import pyplot as plt In [2]: plt.rcParams["figure.figsize"]OutputOut[2]: [6.4, 4.8]
A regular expression is a sequence of characters that define a search pattern. In this program, we will use these regular expressions to filter valid and invalid emails.We will define a Pandas series with different emails and check which email is valid. We will also use a python library called re which is used for regex purposes.AlgorithmStep 1: Define a Pandas series of different email ids. Step 2: Define a regex for checking validity of emails. Step 3: Use the re.search() function in the re library for checking the validity of the email.Example Codeimport pandas as pd import re ... Read More
To calculate the z score for grouped data, we can use ave function and scale function. For example, if we have a data frame called df that contains a grouping coloumn say GROUP and a numerical column say Response then we can use the below command to calculate the z score for this data −ave(df$Response,df$GROUP,FUN=scale)ExampleConsider the below data frame − Live Demogrp
We can first create bars and then, by using set_color, we can set the color of the bars.StepsPass two lists consisting of four elements, into the bars method argument.Step 1 returns bars.Return values (0, 1, 2, 3) can be set with different colors, using set_color() method. Green, Black, Red color will be set and one bar will have the default color.To show the figure, use plt.show() method.Examplefrom matplotlib import pyplot as plt bars = plt.bar([1, 2, 3, 4], [1, 2, 3, 4]) bars[0].set_color('green') bars[1].set_color('black') bars[2].set_color('red') plt.show()Output
A percentile is a term used in statistics to express how a score compares to other scores in the same set. In this program, we have to find nth percentile of a Pandas series.AlgorithmStep 1: Define a Pandas series. Step 2: Input percentile value. Step 3: Calculate the percentile. Step 4: Print the percentile.Example Codeimport pandas as pd series = pd.Series([10, 20, 30, 40, 50]) print("Series:", series) n = int(input("Enter the percentile you want to calculate: ")) n = n/100 percentile = series.quantile(n) print("The {} percentile of the given series is: {}".format(n*100, percentile))OutputSeries: 0 10 1 ... Read More
In this program, we will calculate the frequency of each element in a Pandas series. The function value_counts() in the pandas library helps us to find the frequency of elements.AlgorithmStep 1: Define a Pandas series. Step 2: Print the frequency of each item using the value_counts() function.Example Codeimport pandas as pd series = pd.Series([10,10,20,30,40,30,50,10,60,50,50]) print("Series:", series) frequency = series.value_counts() print("Frequency of elements:", frequency)OutputSeries: 0 10 1 10 2 20 3 30 4 40 5 30 6 50 7 10 8 60 9 50 10 50 dtype: int64 Frequency of elements: 50 3 10 3 30 2 20 1 40 1 60 1 dtype: int64
Using the FuncAnimation method of matplotlib, we can animate the diagram. We can pass a user defined method where we will be changing the position of the particles, and at the end, we will return plot type.StepsGet the particle's initial position, velocity, force, and size.Create a new figure, or activate an existing figure with figsize = (7, 7).Add an axes to the current figure and make it the current axes, with xlim and ylim.Plot scatter for initial position of the particles.Make an animation by repeatedly calling a function *func*. We can pass a user-defined method that helps to change the ... Read More
In this program, we will find the index position at which a multiple of a given number exists. We will use both the Numpy and the Pandas library for this task.AlgorithmStep 1: Define a Pandas series. Step 2: Input a number n from the user. Step 3: Find the multiples of that number from the series using argwhere() function in the numpy library.Example Codeimport numpy as np listnum = np.arange(1, 20) multiples = [] print("NumList:", listnum) n = int(input("Enter the number you want to find multiples of: ")) for num in listnum: if num % n == ... Read More
Using the figure() method, we can set the current figure.StepsCreate a new figure, or activate an existing figure, with the window title “Welcome to figure 1”.Create a new figure, or activate an existing figure, with the window title “Welcome to figure 2”.Using plt.show(), show the figures.Examplefrom matplotlib import pyplot as plt plt.figure("Welcome to figure 1") plt.figure("Welcome to figure 2") # Active Figure plt.show()Output
The correlation matrix with p-values for an R data frame can be found by using the function rcorr of Hmisc package and read the output as matrix. For example, if we have a data frame called df then the correlation matrix with p-values can be found by using rcorr(as.matrix(df)).ExampleConsider the below data frame − Live Demodf1