Found 33676 Articles for Programming

Displaying horizontal bar graphs using Matplotlib

Prasad Naik
Updated on 16-Mar-2021 11:06:31

909 Views

In this program, we will plot a bar graph using the matplotlib library. The most important Step in solving matplotlib related problems using the matplotlib library is importing the matplotlib library. The syntax is:import matplotlib.pyplot as pltPyplot is a collection of command style functions that make Matplotlib work like MATLAB. We will use the function barh() for plotting the horizontal bar chartsAlgorithmStep 1: Define a list of values. Step 2: Use the barh() function in the matplotlib.pyplot library and define different parameters like height width, etc. Step 3: Label the axes using xlabel() and ylabel(). Step 3: Plot the graph ... Read More

How to show two figures using Matplotlib?

Rishikesh Kumar Rishi
Updated on 16-Mar-2021 11:06:50

10K+ Views

We can use the method, plt.figure(), to create the figures, and then, set their titles by passing strings as arguments.StepsCreate a new figure, or activate an existing figure, with the window title “Welcome to figure 1”.Draw a line using plot() method, over the current figure.Create a new figure, or activate an existing figure, with the window title “Welcome to figure 2”.Draw a line using plot() method, over the current figure.Using plt.show(), show the figures.Examplefrom matplotlib import pyplot as plt plt.figure("Welcome to figure 1") plt.plot([1, 3, 4]) plt.figure("Welcome to figure 2") plt.plot([11, 13, 41]) plt.show()OutputRead More

Plotting a 3d cube, a sphere and a vector in Matplotlib

Rishikesh Kumar Rishi
Updated on 16-Mar-2021 11:06:14

5K+ Views

Get fig from plt.figure() and create three different axes using add_subplot, where projection=3d.Set up the figure title using ax.set_title("name of the figure"). Use the method ax.quiver to plot vector projection, plot3D for cube, and plot_wireframe for sphere after using sin and cos.StepsCreate a new figure, or activate an existing figure.To draw vectors, get a 2D array.Get a zipped object.Add an ~.axes.Axes to the figure as part of a subplot arrangement, with 3d projection, where nrows = 1, ncols = 3 and index = 1.Plot a 3D field of arrows.Set xlim, ylim and zlim.Set the title of the axis (at index ... Read More

Displaying bar graphs using Matplotlib

Prasad Naik
Updated on 16-Mar-2021 11:05:57

311 Views

In this program, we will plot a bar graph using the matplotlib library. The most important Step in solving matplotlib related problems using the matplotlib library is importing the matplotlib library. The syntax is −import matplotlib.pyplot as pltPyplot is a collection of command style functions that make Matplotlib work like MATLABAlgorithmStep 1: Define a list of values. Step 2: Use the bar() function in the matplotlib.pyplot library and define different parameters like height, width, etc. Step 3: Label the axes using xlabel() and ylabel(). Step 3: Plot the graph using show().Example Codeimport matplotlib.pyplot as plt data_x = ['Mumbai', 'Delhi', ... Read More

Plot width settings in ipython notebook

Rishikesh Kumar Rishi
Updated on 16-Mar-2021 11:01:37

658 Views

Using plt.rcParams["figure.figsize"], we can get the width setting.StepsTo get the plot width setting, use plt.rcParams["figure.figsize"] statement.Override the plt.rcParams["figure.figsize"] with a tuple (12, 9).After updating the width, get the updated width using plt.rcParams["figure.figsize"].ExamplesIn IDEExampleimport matplotlib.pyplot as plt print("Before, plot width setting:", plt.rcParams["figure.figsize"]) plt.rcParams["figure.figsize"] = (12, 9) print("Before, plot width setting:", plt.rcParams["figure.figsize"])OutputBefore, plot width setting: [6.4, 4.8] Before, plot width setting: [12.0, 9.0]In IPythonExampleIn [1]: from matplotlib import pyplot as plt In [2]: plt.rcParams["figure.figsize"]OutputOut[2]: [6.4, 4.8]

How to divide each column by a particular column in R?

Nizamuddin Siddiqui
Updated on 16-Mar-2021 11:02:17

15K+ Views

To divide each column by a particular column, we can use division sign (/). For example, if we have a data frame called df that contains three columns say x, y, and z then we can divide all the columns by column z using the command df/df[,3].ExampleConsider the below data frame − Live Demox1

How to have logarithmic bins in a Python histogram?

SaiKrishna Tavva
Updated on 23-Sep-2024 14:30:32

5K+ Views

In Python to create a logarithmic bin, we can use Numpy library to generate logarithmically spaced bins, and using matplotlib for creating a histogram. Logarithmic bins in a Python histogram refer to bins that are spaced logarithmically rather than linearly. We can set the logarithmic bins while plotting histograms by using plt.hist(bin="") Steps to Create Logarithmic Bins To set logarithmic bins in a Python histogram, the steps are as follows. Import Libraries: Importing 'matplotlib' for plotting and 'numpy' for performing numerical computations. ... Read More

Changing the color of an axis in Matplotlib

Rishikesh Kumar Rishi
Updated on 16-Mar-2021 11:02:31

9K+ Views

First, we can get the axes. Then, ax.spines could help to set the color by specifying the name of the axes, i.e., top, bottom, right and left.StepsAdd an axes to the current figure and make it the current axes.Using step 1 axes, we can set the color of all the axes.Using ax.spines[axes].set_color(‘color’), set the color of the axes. Axes could be bottom, top, right, and left. Color could be yellow, red, black, and blue.To show the figure, use the plt.show() method.Examplefrom matplotlib import pyplot as plt ax = plt.axes() ax.spines['bottom'].set_color('yellow') ax.spines['top'].set_color('red') ax.spines['right'].set_color('black') ax.spines['left'].set_color('blue') plt.show()OutputRead More

How to use regular expressions (Regex) to filter valid emails in a Pandas series?

Prasad Naik
Updated on 16-Mar-2021 11:00:23

795 Views

A regular expression is a sequence of characters that define a search pattern. In this program, we will use these regular expressions to filter valid and invalid emails.We will define a Pandas series with different emails and check which email is valid. We will also use a python library called re which is used for regex purposes.AlgorithmStep 1: Define a Pandas series of different email ids. Step 2: Define a regex for checking validity of emails. Step 3: Use the re.search() function in the re library for checking the validity of the email.Example Codeimport pandas as pd import re ... Read More

Pandas program to convert a string of date into time

Prasad Naik
Updated on 16-Mar-2021 11:02:13

207 Views

In this program, we will convert a date string like "24 August 2020" to 2020-08-24 00:00:00. We will use the to_datetime() function in pandas library to solve this task.AlgorithmStep 1: Define a Pandas series containing date string. Step 2: Convert these date strings into date time format using the to_datetime format(). Step 3: Print the results.Example Codeimport pandas as pd series = pd.Series(["24 August 2020", "25 December 2020 20:05"]) print("Series: ", series) datetime = pd.to_datetime(series) print("DateTime Format: ", datetime)OutputSeries: 0            24 August 2020 1    25 December 2020 20:05 dtype: object DateTime Format: 0   2020-08-24 00:00:00 1   2020-12-25 20:05:00 dtype: datetime64[ns]

Advertisements