Found 26504 Articles for Server Side Programming

How can I set the 'backend' in matplotlib in Python?

Rishikesh Kumar Rishi
Updated on 16-Mar-2021 10:08:06

723 Views

We can use matplotlib.rcParams['backend'] to override the backend value.StepsUsing get_backend() method, return the name of the current backend, i.e., default name.Now override the backend name.Using get_backend() method, return the name of the current backend, i.e., updated name.Exampleimport matplotlib print("Before, Backend used by matplotlib is: ", matplotlib.get_backend()) matplotlib.rcParams['backend'] = 'TkAgg' print("After, Backend used by matplotlib is: ", matplotlib.get_backend())OutputBefore, Backend used by matplotlib is: GTK3Agg After, Backend used by matplotlib is: TkAgg

Scatter plot and Color mapping in Python

Rishikesh Kumar Rishi
Updated on 16-Mar-2021 10:07:43

766 Views

We can create a scatter plot using the scatter() method and we can set the color for every data point.StepsCreate random values (for x and y) in a given shape, using np.random.rand() method.Create a scatter plot of *y* vs. *x* with varying marker size and/or color, using the scatter method where color range would be in the range of (0, 1000).Show the figure using plt.show().Exampleimport matplotlib.pyplot as plt import numpy as np x = np.random.rand(1000) y = np.random.rand(1000) plt.scatter(x, y, c=[i for i in range(1000)]) plt.show()OutputRead More

How to reset index in Pandas dataframe?

Prasad Naik
Updated on 16-Mar-2021 10:14:44

415 Views

In this program, we will replace or, in other words, reset the default index in the Pandas dataframe. We will first make a dataframe and see the default index and then replace this default index with our custom index.AlgorithmStep 1: Define your dataframe. Step 2: Define your own index. Step 3: Replace the default index with your index using the reset function in Pandas library.Example Codeimport pandas as pd dataframe = {'Name':["Allen", "Jack", "Mark", "Vishal"], 'Marks':[85, 92, 99, 87]} df = pd.DataFrame(dataframe) print("Before using reset_index:", df) own_index = ['a', 'j', 'm', 'v'] df = pd.DataFrame(dataframe, own_index) ... Read More

How to plot two dotted lines and set marker using Matplotlib?

Prasad Naik
Updated on 16-Mar-2021 10:15:42

2K+ Views

In this program, we will plot two lines using the matplot library. Before starting to code, we need to first import the matplotlib library using the following command −Import matplotlib.pyplot as pltPyplot is a collection of command style functions that make matplotlib work like MATLAB.AlgorithmStep 1: Import matplotlib.pyplot Step 2: Define line1 and line2 points. Step 3: Plot the lines using the plot() function in pyplot. Step 4: Define the title, X-axis, Y-axis. Step 5: Display the plots using the show() function.Example Codeimport matplotlib.pyplot as plt line1_x = [10, 20, 30] line1_y = [20, 40, 10] line2_x = ... Read More

How to draw different shapes using the Python Turtle library?

Prasad Naik
Updated on 16-Mar-2021 10:08:58

3K+ Views

In this program, we will draw different shapes using the Turtle library in Python. Turtle is a python feature like a drawing board, which lets you command a turtle to draw all over it. The different shapes that we are going to draw are square, rectangle, circle and a hexagon.AlgorithmStep 1: Take lengths of side for different shapes as input.Step 2: Use different turtle methods like forward() and left() for drawing different shapes.Example Codeimport turtle t = turtle.Turtle() #SQUARE side = int(input("Length of side: ")) for i in range(4):    t.forward(side)    t.left(90) #RECTANGLE side_a = int(input("Length of ... Read More

Change figure window title in pylab(Python)

Rishikesh Kumar Rishi
Updated on 16-Mar-2021 10:07:24

3K+ Views

Using pylab.gcf(), we can create a fig variable and can set the fig.canvas.set_window_title('Setting up window title.') window title.StepsUsing gcf() method, get the current figure. If no current figure exists, a new one is created using `~.pyplot.figure()`.Set the title text of the window containing the figure, using set_window_title() method.. Note that this has no effect if there is no window (e.g., a PS backend).ExamplePlease use Ipython and follow the steps given below -In [1]: from matplotlib import pylab In [2]: fig = pylab.gcf() In [3]: fig.canvas.set_window_title('Setting up window title.')OutputRead More

Python program to compare two Pandas series

Prasad Naik
Updated on 16-Mar-2021 09:55:48

603 Views

In this program, we will declare two Pandas series and compare their elements. Before we solve the problem, we need to import the Pandas library into our local IDE. This can be done by installing Pandas on our local machine. The command for installing Pandas is −pip install pandasInputSeries1 = [2,4,6,8,10]Series2 = [1,3,5,7,9]AlgorithmStep 1: Define two Pandas series using the Series() function of Pandas library.Step 2: Compare the series using greater than, less than, and equal-to operators.Example Codeimport pandas as pd series1 = pd.Series([2,4,6,8,10]) series2 = pd.Series([1,3,5,7,9]) print("Greater Than: ",series1>series2) print("Less Than: ",series1

How to convert negative values in a matrix to 0 in R?

Nizamuddin Siddiqui
Updated on 16-Mar-2021 10:10:24

5K+ Views

To convert negative values in a matrix to 0, we can use pmax function. For example, if we have a matrix called M that contains some negative and some positive and zero values then the negative values in M can be converted to 0 by using the command pmax(M,0).ExampleConsider the below data frame − Live DemoM1

How to minus one column from another in an R matrix?

Nizamuddin Siddiqui
Updated on 16-Mar-2021 07:44:09

6K+ Views

To minus one column from another in an R matrix, we first need to read the matrix as a data frame using as.data.frame then find minus the columns using minus sign and accessing the column of the data frame. To understand how it can be done look at the steps in below examples.ExampleConsider the below data frame − Live DemoM1

How to sort each row of an R data frame in increasing order?

Nizamuddin Siddiqui
Updated on 16-Mar-2021 07:35:06

2K+ Views

To sort each row of an R data frame in increasing order, we can use apply function for sorting the columns and then transpose the output. For example, if we have a data frame called df that contains 5 columns then each row of df can be sorted in increasing order by using the command t(apply(df,1,sort)).Example1Consider the below data frame − Live Demox1

Advertisements