Draw a Heart with Pylab

Rishikesh Kumar Rishi
Updated on 03-Aug-2021 12:12:27

1K+ Views

To draw a heart with pylab/pyplot, we can follow the steps given below −StepsSet the figure size and adjust the padding between and around the subplots.Create x, y1 and y2 data points using numpy.Fill the area between (x, y1) and (x, y2) using fill_between() method.Place text on the plot using text() method at (0, -1.0) point.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 x = np.linspace(-2, 2, 1000) y1 = np.sqrt(1 - (abs(x) - 1) ** 2) y2 = -3 * np.sqrt(1 - ... Read More

Save an Image with Matplotlib Pyplot

Rishikesh Kumar Rishi
Updated on 03-Aug-2021 12:10:48

5K+ Views

To save an image with matplotlib.pyplot.savefig(), 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.Plot x and y data points using plot() method.To save the figure, use savefig() method.Exampleimport numpy as np import matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True x = np.linspace(-np.pi, np.pi, 100) plt.plot(x, np.sin(x) * x, c='red') plt.savefig("myimage.png")OutputWhen we execute the code, it will save the following image as "myimage.png" in the Project directory.Read More

Sum of Numerical Columns Based on Categorical Values in R Data Frame

Nizamuddin Siddiqui
Updated on 03-Aug-2021 09:19:39

183 Views

To find the sum of numerical columns based on the combination of values in categorical columns in R data frame, we can follow the below steps −First of all, create a data frame.Then, find the sum of numerical columns based on the combination of values in categorical columns by using recast function of reshape2 package with sum function.Create the data frameExampleLet's create a data frame as shown below − Live Demo> x1 x2 x3 x4 f1 f2 df dfOn executing, the above script generates the below output(this output will vary on your system due to randomization) −Output  x1 x2 x3 x4 ... Read More

Practice Questions on Time Complexity Analysis in C++

sudhir sharma
Updated on 02-Aug-2021 12:05:47

10K+ Views

Time complexity of any algorithm is the time taken by the algorithm to complete. It is an important metric to show the efficiency of the algorithm and for comparative analysis. We tend to reduce the time complexity of algorithm that makes it more effective.Example 1Find the time complexity of the following code snippetsfor(i= 0 ; i < n; i++){    cout

Determine Recursively Whether a Given Number is Even or Odd in Go

Rishikesh Kumar Rishi
Updated on 02-Aug-2021 07:09:21

358 Views

StepsTake a number from the user and store it in a variable.Pass the number as an argument to a recursive function.Define the base condition as the number to be lesser than 2.Otherwise, call the function recursively with the number minus 2.Then, return the result and check if the number is even or odd.Print the final result.Enter a number: 124Number is even!Enter a number: 567Number is odd!Example Live Demopackage main import (    "fmt" ) func check(n int) bool{    if n < 2 {       return n % 2 == 0    }    return check(n - 2) } ... Read More

Use Chmod Recursively on Linux

Mukul Latiyan
Updated on 02-Aug-2021 06:45:04

439 Views

You might have been in a scenario where you are using a Linux as your main operating system and then you try to create or edit a file and the Linux terminal responds with something like “Permission deny” error. In typical sense, such an error is related to insufficient permissions that your current user is having and can be solved by setting the correct file permissions or changing the owner.In Linux, the files are controlled through the file permissions, ownership and attributes, which in turn makes sure that only authorized users and processes can access files and directories.Before understanding how ... Read More

Introduction to Arduino Time Library

Yash Sanghvi
Updated on 02-Aug-2021 06:40:33

9K+ Views

The Time library provides you with timekeeping functionality on the Arduino. The latest version of the library is documented here.To install it, search for Time in the Library Manager and install the library by Michael Margolis.You’ll have to scroll a bit to find this library.Once the library is installed, if you go to File → Examples → Time, you will be able to see several examples of integrating this library with various sources: GPS, NTP, RTC, etc.The basic idea is that you can set time using the functions −setTime(hours, minutes, seconds, days, months, years);OR, setTime(t);where t is the special time_t ... Read More

Browse Arduino Libraries by Category on Arduino Website

Yash Sanghvi
Updated on 02-Aug-2021 06:36:54

217 Views

Follow the steps given below to browse Arduino libraries by category on Arduino website −Go to http://arduino.cc/Click Documentation → ReferenceClick Libraries from the left menu.The libraries can now be found in the categorized form on this pageClick the category of your interest and explore the available libraries.

Goto in Arduino

Yash Sanghvi
Updated on 02-Aug-2021 06:34:22

7K+ Views

goto is a control structure in Arduino, like in C, and it is used to transfer the program flow to another point in the program. It is highly discouraged, as many programmers agree that you can write every algorithm you want without the use of goto.Excessive use of goto makes it very difficult to debug programs, or, in some cases, creates program flows which are impossible to debug. It is assumed that you will read further only if you absolutely have to use goto.SyntaxThe syntax for using goto is −goto label; label:    //statementsExampleThe following example demonstrates this −void ... Read More

Reference and Dereference Operator in Arduino

Yash Sanghvi
Updated on 02-Aug-2021 06:32:39

2K+ Views

The reference (&) and dereference operators (*) in Arduino are similar to C. Referencing and dereferencing are used with pointers.If x is a variable, then its address is represented by &x.Similarly, if p is a pointer, then the value contained in the address pointed to by p is represented by &p.Examplevoid setup() {    // put your setup code here, to run once:    Serial.begin(9600);    Serial.println();    int x = 10;    int *p;    p = &x; //p now contains the address of x    Serial.print("The value stored in the address pointed by p is: ");Serial.println(*p); } ... Read More

Advertisements