Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

1,016 Articles Published

Articles by Rishikesh Kumar Rishi

Page 101 of 102

How to rotate X-axis tick labels in Pandas bar plot?

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 15-Mar-2021 8K+ Views

Using plt.xticks(x, labels, rotation='vertical'), we can rotate our tick’s label.StepsCreate two lists, x, and y.Create labels with a list of different cities.Adjust the subplot layout parameters, where bottom = 0.15.Add a subplot to the current figure, where nrow = 1, ncols = 2 and index = 1.Plot the line using plt.plot(), using x and y (Step 1).Get or set the current tick locations and labels of the X-axis. Pass no arguments to return the current values without modifying them, with x and label data.Set or retrieve auto-scaling margins, value is 0.2.Set the title of the figure at index 1, the ...

Read More

How to make a discrete colorbar for a scatter plot in matplotlib?

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 15-Mar-2021 8K+ Views

Using plt.colorbar(ticks=np.linspace(-2, 2, 5)), we can create a discrete color bar.StepsReturn random floats in the half open interval, i.e., x, using np.random.random method.Return random floats in the half open interval, i.e., y, using np.random.random method.Return random integers from `low` (inclusive) to `high` (exclusive), i.e., z, using np.random.randint(-2, 3, 20) method.Set the X-axis label using plt.xlabel().Set the Y-axis label using plt.ylabel().Use the built-in rainbow colormap.Generate a colormap index based on discrete intervals.A scatter plot of *y* vs. *x* with varying marker size and/or color, with x, y and z are created (Steps 1, 2, 3).Create a colorbar for a ScalarMappable instance, ...

Read More

How to maximize a plt.show() window using Python?

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 15-Mar-2021 5K+ Views

Using plt.get_current_fig_manager() and mng.full_screen_toggle() methods, we can maximise a plot.StepsAdd a subplot to the current figure, where nrow = 1, ncols = 1 and index = 1.Create a pie chart using list [1, 2, 3] and pie() method.Return the figure manager of the current figure, using get_current_fig_manager() method. The figure manager is a container for the actual backend-depended window that displays the figure on the screen.Create an abstract base class to handle drawing/rendering operations using the full_screen_toggle() method.Use plt.show() to show the figure.Exampleimport matplotlib.pyplot as plt plt.subplot(1, 1, 1) plt.pie([1, 2, 3]) mng = plt.get_current_fig_manager() mng.full_screen_toggle() plt.show()Output

Read More

How to share x axes of two subplots after they have been created in Matplotlib?

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 15-Mar-2021 2K+ Views

First, we can create two axes using the subplot method where nrows=2, ncols=1. That means, we can have two indices to plot the desired plot. We can use ax1.get_shared_x_axes().join(ax1, ax2) method for our plot.StepsCreate two lists of the numbers.Add a subplot to the current figure, ax1, where nrows = 2, ncols = 1, and index is 1 for ax1.Add a subplot to the current figure, ax2, where nrows = 2, ncols = 1, and index is 2 for ax2.Plot x and y using points that are created in step 1.Using get_shared_x_axes().join(ax1, ax2), return a reference to the shared axes Grouper ...

Read More

Adding value labels on a matplotlib bar chart

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 15-Mar-2021 23K+ Views

In this program, we can initialize some input values and then try to plot a bar using those values. We can instantiate a figure and axis so that we could set the label, ticks, and annotate the height and width of the bar.StepsMake a list of years.Make a list of populations in that year.Get the number of labels using np.arrange(len(years)) method.Set the width of the bars.Create fig and ax variables using subplots() method, where default nrows and ncols are 1.Set the Y-axis label of the figure using set_ylabel().Set the title of the figure, using set_title().Set the X-ticks with x that ...

Read More

Plot different colors for different categorical levels using matplotlib

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 15-Mar-2021 1K+ Views

We can plot a diagram where a number of students will be plotted on the X-axis and the marks obtained by them will be plotted on the Y-axis. Also, we can set the color for different marks obtained by the students.StepsMake a list of the number of students.Make a list of marks that have been obtained by the students.To represent the color of each scattered point, we can have a list of colors.Using Panda, we can have a list representing the axes of the data frame.Create fig and ax variables using subplots method, where default nrows and ncols are 1.Set ...

Read More

What is the difference between drawing plots using plot, axes or figure in matplotlib?

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 15-Mar-2021 3K+ Views

Let’s understand the difference between plot, axes, and figure with an example.Plot − Plot helps to plot just one diagram with (x, y) coordinates.Axes − Axes help to plot one or more diagrams in the same window and sets the location of the figure.Figure − This method provides a top-level container for all the plot elements.We can follow these steps to replicate the differences among them −Create a new figure, or activate an existing figure, using plt.figure().Add an axis to the figure as part of a subplot arrangement, using plt.add_subplot(xyz) where x is nrows, y is ncols and z is ...

Read More

Plotting with seaborn using the matplotlib object-oriented interface

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 15-Mar-2021 327 Views

Seaborn is used to visualizing the random distribution and we can use matplotlib interface to show this distribution over a diagram.We can take the following steps to show the diagram −Figure level interface for drawing distribution plots onto a Face Grid. This function provides access to several approaches for visualizing the univariate or bivariate distribution of data, including subsets of data defined by semantic mapping and faceting across multiple subplots.List of numbers can be passed in the above-defined method, i.e., displot().To show the diagram, plt.show() can be used whereas plot was drawn using Seaborn.Exampleimport matplotlib.pyplot as plt import seaborn as ...

Read More

How to set the matplotlib figure default size in ipython notebook?

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 15-Mar-2021 5K+ Views

To set the matplotlib figure default size in iPython, use the following steps −To check the default figure size, use plt.rcParams["figure.figsize"] over the ipython shell.Now to set the figure size, override the plt.rcParams["figure.figsize"] variable with a tuple i.e., (20, 10).After overriding the plt.rcParams["figure.figsize"] variable, you can use it to get changed figure size.Exampleimport matplotlib.pyplot as plt print("Before, figure default size is: ", plt.rcParams["figure.figsize"]) plt.rcParams["figure.figsize"] = (20, 10) print("After, figure default size is: ", plt.rcParams["figure.figsize"])OutputBefore, figure default size is: [6.4, 4.8] After, figure default size is: [20.0, 10.0]

Read More

Fill between two vertical lines in matplotlib

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 15-Mar-2021 2K+ Views

To fill color between two vertical lines, use the following steps −Using plt.subplots() method, create a figure and a set of subplots. This utility wrapper makes it convenient to create common layouts of subplots, including the enclosing figure object, in a single call.To draw two vertical lines, initialize x = 3 and x = 5.Using the created ax, axvspan would help to add vertical span(rectangle) across the axes.This rectangle spans from xmin to xmax horizontally, and, by default, the whole Y-axis vertically.To show the figure, use the plt.show() method.Exampleimport matplotlib.pyplot as plt fig, ax = plt.subplots() line1 = ...

Read More
Showing 1001–1010 of 1,016 articles
Advertisements