To embed small plots inside subplots, we can take the following Steps −Using subplots() method, create a figure and a set of subplots (fig, ax1).On ax1, plot a line with color red, line width=4, label=”outer plot”.Using add_axes(), add an axis, i.e., ax2 with l, b, h and w values.Plot the same points (Step 2) usins the plot() method, with color green, line width=3, label=”inside plot”.Set the legend on both the plots using the legend() method.To display the figure, use the show() method.Examplefrom matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True fig, ax1 = plt.subplots() ax1.plot([1, 4, ... Read More
To change the figuresize using Seaborn factorplot, we can take the following Steps −Load the exercise data using load_dataset() method.Using factorplot() method, change figure size by customising the size and aspect values.To display the figure, use the show() method.Exampleimport seaborn as sns from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True exercise = sns.load_dataset("exercise") sns.factorplot("kind", "pulse", "diet", exercise, kind="point", size=5, aspect=2) plt.show()Output
To set the font size of matplotlib axis legend, we can take the following steps −Create the points for x and y using numpy.Plot x and y using the plot() method with label y=sin(x).Title the plot using the title() method.To set the fontsize, we can override rcParams legend fontsize by value 20.Use the legend() method, and fit the legend at the top-right position.To display the figure, use the show() method.Exampleimport numpy as np from matplotlib import pyplot as plt import matplotlib plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True x = np.linspace(1, 10, 50) y = np.sin(x) plt.plot(x, y, c="red", lw=7, label="y=sin(x)") ... Read More
ProblemJavaScript function that takes in two arrays, arr1 and arr2 of intervals which are pairwise disjoint and in sorted order.A closed interval [a, b] (with a
ProblemWe are required to write a JavaScript function that takes in an array of integers as the first and the only argument. Our function should return true if and only if we can partition the array into three non-empty parts with equal sums, false otherwise.For example, if the input to the function is −const arr = [3, 3, 6, 5, -2, 2, 5, 1, -9, 4];Then the output should be −const output = true;Output ExplanationBecause, 3 + 3 = 6 = 5 - 2 + 2 + 5 + 1 - 9 + 4ExampleThe code for this will be − Live ... Read More
ProblemWe are required to write a JavaScript function that takes in a binary arr (array that contains only 0 or 1), arr, as the first argument, and a number, num, as the second argument.We can change at most num 0s present in the array to 1s, and our function should return the length of the longest (contiguous) subarray that contains only 1s after making these changes.For example, if the input to the function is −const arr = [1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0]; const num = 2;Then the output should be −const output = 6;Output ... Read More
ProblemWe are required to write a JavaScript function that takes in an array of strings, arr, as the first and the only argument.Our function is supposed to return an array of all characters that show up in all strings within the array arr (including duplicates).For example, if a character occurs 2 times in all strings but not 3 times, we need to include that character 2 times in the final answer.For example, if the input to the function is −const arr = ['door', 'floor', 'crook'];Then the output should be −const output = ['r', 'o', 'o'];ExampleThe code for this will be ... Read More
ProblemWe are required to write a JavaScript function that takes in a 2-D array of numbers, arr, as the only argument.The numbers in the array can be −the value 0 which represents an empty cell;the value 1 which represents a fresh tomato;the value 2 which represents a rotten tomato.Every minute, any fresh tomato that is adjacent (4-directionally) to a rotten tomato becomes rotten.Our function is supposed to return the minimum number of minutes that must elapse until no cell has a fresh tomato. If this is impossible, we should return -1 instead.For example, if the input to the function is ... Read More
ProblemWe are required to write a JavaScript function that takes in an array of literals, arr, as the first argument. The second argument to our function will be a number, num. Our function should count and return the number of subarrays of the array that contains exactly num distinct elements.For example, if the input to the function is −const arr = [12, 15, 12, 15, 18]; const num = 2;Then the output should be −const output = 7;Output ExplanationSubarrays formed with exactly 2 different elements −[12, 15], [15, 12], [12, 15], [15, 18], [12, 15, 12], [15, 12, 15], [12, ... Read More
ProblemWe are required to write a JavaScript function that takes in two numbers, m and n, as the first and the second argument.Our function is supposed to count the number of minimum operations required to reach n from m, using only these two operations −Double − Multiply the number on the display by 2, or;Decrement − Subtract 1 from the number on the display.For example, if the input to the function is −const m = 5; const n = 8;Then the output should be −const output = 8;Output Explanation:Because the operations are −5 → 4 → 8ExampleThe code for this ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP