Matplotlib Legends in Subplot

Rishikesh Kumar Rishi
Updated on 26-Oct-2023 03:33:10

29K+ Views

To add legends in a subplot, we can take the following Steps −Using numpy, create points for x, y1, y2 and y3.Create a figure and a set of subplots, using the subplots() method, considering 3 subplots.Plot the curve on all the subplots(3), with different labels, colors. To place the legend for each curve or subplot adding label.To activate label for each curve, use the legend() method.To display the figure, use the 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, 100) y1 = np.sin(x) y2 = np.cos(x) y3 ... Read More

Print Single and Multiple Variables in Python

AmitDiwan
Updated on 26-Oct-2023 03:30:56

27K+ Views

To easily display single and multiple variables in Python, use the print() statement. For multiple variables, use the comma operators. Variables are reserved memory locations to store values. It means that when you create a variable, you reserve some space in the memory. Based on the data type of a variable, the interpreter allocates memory and decides what can be stored in the reserved memory. Therefore, by assigning different data types to the variables, you can store integers, decimals or characters in these variables. Print Single Variable in Python To display a single variable, simply use the print() method − ... Read More

What is a Syntax Tree

Ginni
Updated on 26-Oct-2023 03:28:34

30K+ Views

Tree in which each leaf node describes an operand & each interior node an operator. The syntax tree is shortened form of the Parse Tree.Example1 − Draw Syntax Tree for the string a + b ∗ c − d.Rules for constructing a syntax treeEach node in a syntax tree can be executed as data with multiple fields. In the node for an operator, one field recognizes the operator and the remaining field includes a pointer to the nodes for the operands. The operator is known as the label of the node. The following functions are used to create the nodes ... Read More

C++ Stream Classes Structure

sudhir sharma
Updated on 26-Oct-2023 03:24:39

27K+ Views

In C++ stream refers to the stream of characters that are transferred between the program thread and i/o.Stream classes in C++ are used to input and output operations on files and io devices. These classes have specific features and to handle input and output of the program.The iostream.h library holds all the stream classes in the C++ programming language.Let's see the hierarchy and learn about them, Now, let’s learn about the classes of the iostream library.ios class − This class is the base class for all stream classes. The streams can be input or output streams. This class defines members that ... Read More

Calculate Time of Operation in Arduino

Yash Sanghvi
Updated on 26-Oct-2023 02:34:16

29K+ Views

Often, you need to measure the time your microcontroller takes to perform a particular task. You can use the millis() function of Arduino to measure the time. This function returns the number of milliseconds passed since your board started running the current program. Therefore, to calculate the time taken by an operation, you can call millis() before and after your operation, and take the difference of the two values.An example implementation is given below −Examplevoid setup() {    // put your setup code here, to run once:    Serial.begin(9600);    long int t1 = millis();    task_whose_time_is_to_be_measured();    long int ... Read More

Run Java Package Program

Ankitha Reddy
Updated on 26-Oct-2023 02:32:02

34K+ Views

Let us look at an example that creates a package called animals. It is a good practice to use names of packages with lower case letters to avoid any conflicts with the names of classes and interfaces.Following package example contains interface named animals −/* File name : Animal.java */ package animals; interface Animal {    public void eat();    public void travel(); }Now, let us implement the above interface in the same package animals −package animals; /* File name : MammalInt.java */ public class MammalInt implements Animal {    public void eat() {       System.out.println("Mammal eats");    } ... Read More

Set Parent State from Children Component in ReactJS

Shubham Vora
Updated on 26-Oct-2023 02:29:41

38K+ Views

In ReactJS, we can set the state in the child component by passing the values as a prop of the child component. Sometimes, we require to set the state from the children component to the parent component in ReactJS. We can create a state handler function in the parent component and pass it as a prop of the child component. After that, we can use the child component function to set the parent component's state. In such a way, we can manage the state of the parent component from the child component. Set parent state from children component in functional ... Read More

Use & and && Operators in MATLAB

Manish Kumar Saini
Updated on 25-Oct-2023 15:48:33

493 Views

In MATLAB, there are various types of operators used to perform different operations. Two such operators are "&" and "&&". The "&" and "&&" operators are the logical operators used to perform element wise logical AND operations. However, they are absolutely different from each other on the basis of their behavior. Read this article to understand the basics of "&" and "&&" operators in MATLAB along with their applications in MATLAB programming. What is & Operator in MATLAB? In MATLAB, the "&" operator is an element-wise operator used to perform logical AND operation between two arrays. If we use ... Read More

Use TeX/LaTeX Math Mode Symbols in MATLAB Figures

Manish Kumar Saini
Updated on 25-Oct-2023 15:44:37

328 Views

MATLAB is a powerful tool to perform various mathematical tasks such as performing operations, plotting charts and figures, manipulating matrices, and more. In digital mathematical tools like MATLAB, there is a typesetting system called "TeX" which is used to communicate and publish mathematical equations and structures. This typesetting system was developed by Donald Knuth. In this tutorial, I will explain the TeX system in LaTeX math mode and the use of TeX symbols in legends and labels in a plot or figure in MATLAB. What is TeX in MATLAB? TeX is a typesetting system used to publish mathematical equations and ... Read More

Write Data to Excel Spreadsheets in MATLAB

Manish Kumar Saini
Updated on 25-Oct-2023 15:42:34

682 Views

MATLAB provides various built-in functions that enable us to write data in the form of tables, matrices, cell arrays, etc. to an Excel file. Read this article to learn the process of writing data to Excel spreadsheets in MATLAB. The following are some commonly used methods to write data to excel spreadsheets using MATLAB − Using the "writetable" Function Using the "xlswrite" Function Using the "writematrix" Function Using the "writecell" Function Let us discuss each of these methods in detail with the help of examples. Using "writetable" Function in MATLAB In MATLAB, the "writetable" is a built-in function ... Read More

Advertisements