Found 26504 Articles for Server Side Programming

Automatically position text box in Matplotlib

Rishikesh Kumar Rishi
Updated on 09-Apr-2021 08:25:06

738 Views

To position a textbox automatically in matplotlib, we can take the following Steps −Create xpoints from 1 to 2 and 100 samples.Create y1points and y2points using xpoints (Step 1) and numpy.Plot xpoints, y1points and y2points using the plot() method.To set the label, use the legend() method. It will help to position the text box.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 xpoints = np.linspace(1, 2, 100) y1points = np.log(xpoints) y2points = np.exp(xpoints) plt.plot(xpoints, y1points, label="Log") plt.plot(xpoints, y2points, label="Exp") plt.legend() plt.show()OutputRead More

What are the differences between add_axes and add_subplot in Matplotlib?

Rishikesh Kumar Rishi
Updated on 09-Apr-2021 08:24:42

513 Views

Definingadd_axes − Add an axes to the figure.add_subplot − Add an axes to the figure as part of a subplot arrangement.StepsCreate a new figure, or activate an existing figure, using the figure() method.Add an axes to the figure as part of a subplot arrangement where nrows=2, ncols=2. At index 1, add the title "subtitle1" and at index 2, add the title "subplot2".Create points for four rectangles and use add_axes() method to add an axes to the figure.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 = plt.figure() fig.add_subplot(221) plt.title("subplot1") fig.add_subplot(222) ... Read More

How to change the curve using radiobuttons in Matplotlib?

Rishikesh Kumar Rishi
Updated on 09-Apr-2021 08:21:36

383 Views

To change the color of a line using radiobuttons, we can take the following steps −Create x, sin and cos data points using numpy.Adjust the figure size and padding between and around the subplots.Create a figure and a set of subplots using the subplots() method.Plot curve with x and y data points using the plot() method.Add an axes to the current figure and make it the current axes, using the axes() method.Add a radio button to the current axes.To change the curve with radionbutton, we can use the change_curve() method that can be passed in on_clicked() method.To display the figure, use the show() method.Exampleimport numpy ... Read More

Pythonic way of detecting outliers in one dimensional observation data using Matplotlib

Rishikesh Kumar Rishi
Updated on 09-Apr-2021 08:19:37

195 Views

To detect outliers in one dimensional observation data, we can take the following Steps −Create spread, center, flier_high and flier_low.Using the above data (Step 1), we can calculate data.Use the suplots() method to create a figure and a set of subplots, i.e., fig1 and ax1.Set the title of ax1.Now using the boxplot() method and data, make a box and a whisker plot. Beyond the whiskers, data are considered outliers and are plotted as individual points.To display the figure, use the 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 np.random.seed(19680801) spread ... Read More

How to plot the lines first and points last in Matplotlib?

Rishikesh Kumar Rishi
Updated on 10-Apr-2021 11:40:58

542 Views

To plot the lines first and points last, we can take the following Steps −Create xpoints, y1points and y2points using numpy, to draw lines.Plot the curves using the plot() method with x, y1 and y2 points.Draw the scatter points using the scatter 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 xpoints = np.linspace(1, 1.5, 10) y1points = np.log(xpoints) y2points = np.exp(xpoints) plt.plot(xpoints, y1points) plt.plot(xpoints, y2points) for i in xpoints:    plt.scatter(i, np.random.randint(10)) plt.show()OutputRead More

While and For Range in Rust Programming

Mukul Latiyan
Updated on 05-Apr-2021 08:29:42

190 Views

We know that Rust provides a loop keyword to run an infinite loop. But the more traditional way to run loops in any programming language is with either making use of the while loop or the for range loop.While LoopThe while loop is used to execute a code of block until a certain condition evaluates to true. Once the condition becomes false, the loop breaks and anything after the loop is then evaluated. In Rust, it is pretty much the same.ExampleConsider the example shown below:Live Demofn main() {    let mut z = 1;    while z < 20 { ... Read More

Vectors in Rust Programming

Mukul Latiyan
Updated on 05-Apr-2021 08:23:50

440 Views

Vectors in Rust are like re-sizable arrays. They are used to store objects that are of the same type and they are stored contiguously in memoryLike Slices, their size is not known at compile-time and can grow or shrink accordingly. It is denoted by Vec in RustThe data stored in the vector is allocated on the heap.ExampleIn the below example, a vector named d is created using the Vec::new(); function that Rust provides.fn main() {    let mut d: Vec = Vec::new();    d.push(10);    d.push(11);    println!("{:?}", d);    d.pop();    println!("{:?}", d); }We push the elements into a ... Read More

Using Threads in Rust Programming

Mukul Latiyan
Updated on 05-Apr-2021 08:13:32

787 Views

We know that a process is a program in a running state. The Operating System maintains and manages multiple processes at once. These processes are run on independent parts and these independent parts are known as threads.Rust provides an implementation of 1:1 threading. It provides different APIs that handles the case of thread creation, joining, and many such methods.Creating a new thread with spawnTo create a new thread in Rust, we call the thread::spawn function and then pass it a closure, which in turn contains the code that we want to run in the new thread.ExampleConsider the example shown below:use ... Read More

Use Declarations in Rust Programming

Mukul Latiyan
Updated on 05-Apr-2021 08:10:30

574 Views

Use Declarations in Rust are used to bind a full path to a new name. It can be very helpful in cases where the full path is a bit long to write and invoke.In normal cases, we were used to doing something like this:use crate::deeply::nested::{    my_function,    AndATraitType }; fn main() {    my_function(); }We invoked the use declaration function by the name of the function my_function. Use declaration also allows us to bind the full path to a new name of our choice.ExampleConsider the example shown below:// Bind the `deeply::nested::function` path to `my_function`. use deeply::nested::function as my_function; ... Read More

Unsafe Operation in Rust Programming

Mukul Latiyan
Updated on 05-Apr-2021 08:06:59

228 Views

Unsafe Operations are done when we want to ignore the norm that Rust provides us. There are different unsafe operations that we can use, mainly:dereferencing raw pointersaccessing or modifying static mutable variablescalling functions or methods which are unsafeThough it is not recommended by Rust that we should use unsafe operations at all, we should use them only when we want to bypass the protections that are put in by the compiler.Raw Pointers In Rust, the raw pointers * and the references &T perform almost the same thing, but references are always safe, as they are guaranteed by the compiler to point ... Read More

Advertisements