Rishikesh Kumar Rishi has Published 1156 Articles

How to align rows in a Matplotlib legend with 2 columns?

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 01-Jun-2021 12:09:13

4K+ Views

To align rows in a matplotlib legend with 2 columns, we can take the following stepsSet the figure size and adjust the padding between and around the subplots.Using plot() method, plot lines with the labels line1, line2 and line3.Place a legend on the figure with two columns. Use ncol=2.To display ... Read More

Map values to colors in Matplotlib

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 01-Jun-2021 12:08:53

3K+ Views

To map values to a colors tuple(red, green and blue) in matplotlib, we can take the following steps −Create a list of values from 1.00 to 2.00, count=10.Get linearly normalized data into the vmin and vmax interval.Get an object to map the scalar data to rgba.Iterate the values to map ... Read More

Drawing a network graph with networkX and Matplotlib

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 01-Jun-2021 12:07:37

3K+ Views

To draw a network graph with networkx and matplotlib, plt.show() −Set the figure size and adjust the padding between and around the subplots.Make an object for a dataframe with the keys, from and to.Get a graph containing an edgelist.Draw a graph (Step 3) using draw() method with some node properties.To ... Read More

How do you draw R-style axis ticks that point outward from the axes in Matplotlib?

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 01-Jun-2021 12:07:09

228 Views

To draw R-style (default is regular style) axis ticks that point outward from the axes in matplotlib, we can use rcParams["xticks.direction"]="out" for X-axis.StepsSet the figure size and adjust the padding between and around the subplots.Set outwaord tick points using plt.rcParams.Initialize a variable for the number of data points.Create x and ... Read More

How do I make the width of the title box span the entire plot in Matplotlib?

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 01-Jun-2021 12:06:48

411 Views

To make width of title box span the entire plot in matplotlib, we can take the following stepsSet 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, with color=black and linewidth=7.Get the ... Read More

How do I convert (or scale) axis values and redefine the tick frequency in Matplotlib?

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 01-Jun-2021 12:06:28

2K+ Views

To convert or scale the axis values and redefine the tick frequency in matplotlib, we can make a list of xticks and xtick_labels using xticks() method. Place the axis scale and redefine the tick frequency.StepsSet the figure size and adjust the padding between and around the subplots.Initialize a variable, n, ... Read More

Python Scatter Plot with Multiple Y values for each X

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 01-Jun-2021 11:52:49

8K+ Views

To make a scatter plot with multiple Y values for each X, we can create x and y data points using numpy, zip and iterate them together to create the scatter plot.StepsSet the figure size and adjust the padding between and around the subplots.Create random xs and ys data points ... Read More

What does axes.flat in Matplotlib do?

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 01-Jun-2021 11:47:53

5K+ Views

Axes.flat means a 1D iterator over the array. Let's take an example to see how to use axes.flat.StepsSet the figure size and adjust the padding between and around the subplots.Create a figure and a set of subplots using subplots() method.Create x and y data points using numpy.Use axes.flat and iterate ... Read More

How to write text above the bars on a bar plot (Python Matplotlib)?

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 01-Jun-2021 11:47:36

4K+ Views

To write text above the bars on a bar plot, we can take the following stepsSet the figure size and adjust the padding between and around the subplots.Create lists of year, population and x. Initialize a width variable.Create a figure and a set of subplots using subplots() method.Set ylabels, title, ... Read More

Plot horizontal and vertical lines passing through a point that is an intersection point of two lines in Matplotlib

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 01-Jun-2021 11:47:19

2K+ Views

To plot horizontal and vertical lines passing through a point, we can take the following stepsSet the figure size and adjust the padding between and around the subplots.Create two lines using slopes (m1, m2) and intercepts (c1 and c2). Initialize the slopes and intercepts values.Create x data points using numpy.Plot ... Read More

Advertisements