Rishikesh Kumar Rishi has Published 1156 Articles

Shading an area between two points in a Matplotlib plot

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 06-May-2021 13:25:29

7K+ Views

To shade an area between two points in matplotlib, we can take the following steps−Create x and y data points using numpy.Plot x and y data points, with color=red and linewidth=2.To shade an area parallel to X-axis, initialize two variables, y1 and y2.To add horizontal span across the axes, use ... Read More

Creating a graph with date and time in axis labels with Matplotlib

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 06-May-2021 13:25:04

4K+ Views

To create a graph with date and time in axis labels, we can take the following steps−Create a figure and add a set of subplots.Create x and y data points using numpy.Set date formatter for X-axis.Plot x and y using plot() method.Set the ticks of X-axis.Set the date-time tick labels ... Read More

How to specify values on Y-axis in Python Matplotlib?

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 06-May-2021 13:24:32

12K+ Views

To specify values on Y-axis in Python, we can take the following steps−Create x and y data points using numpy.To specify the value of axes, create a list of characters.Use xticks and yticks method to specify the ticks on the axes with x and y ticks data points respectively.Plot the ... Read More

How to plot 1D data at a given Y-value with PyLab using Matplotlib?

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 06-May-2021 13:24:09

4K+ Views

To plot 1D data at a given Y-value with pyplot, we can take the following steps−Initialize y value.Create x and y data points using numpy. zeros_like helps to return an array of zeros with the same shape and type as a given array and add y-value for y data points.Plot ... Read More

Matplotlib – How to insert a degree symbol into a Python plot?

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 06-May-2021 13:19:02

11K+ Views

To insert a degree symbol into a plot, we can use LaTeX representation.StepsCreate data points for pV, nR and T using numpy.Plot pV and T using plot() method.Set xlabel for pV using xlabel() method.Set the label for temperature with degree symbol using ylabel() method.To display the figure, use show() method.Exampleimport ... Read More

How to get the list of axes for a figure in Pyplot?

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 06-May-2021 13:18:35

5K+ Views

To get a list of axes of a figure, we will first create a figure and then, use get_axes() method to get the axes and set the labels of those axes.Create xs and ys using numpy and fig using figure() method. Create a new figure, or activate an existing figure.Use ... Read More

How to get rid of grid lines when plotting with Seaborn + Pandas with secondary_y?

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 06-May-2021 13:17:02

4K+ Views

To get rid of grid lines when plotting with Pandas with secondary_y, we can take the following steps −Create a data frame using DataFrame wth keys column1 and column2.Use data frame data to plot the data frame. To get rid of gridlines, use grid=False.To display the figure, use show() method.Exampleimport pandas as ... Read More

Matplotlib savefig with a legend outside the plot

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 06-May-2021 13:16:34

3K+ Views

To save a file with legend outside the plot, we can take the following steps −Create x data points using numpy.Plot y=sin(x) curve using plot() method, with color=red, marker="v" and label y=sin(x).Plot y=cos(x), curve using plot() method, with color=green, marker="x" and label y=cos(x).To place the legend outside the plot, use bbox_to_anchor(.45, 1.15) ... Read More

How to change the scale of an existing table in Matplotlib?

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 06-May-2021 13:16:13

3K+ Views

To change scale of a table, we can use the scale() method. Steps −Create a figure and a set of subplots, nrows=1 and ncols=1.Create a random data using numpy.Make columns value.Make the axis tight and off.Initialize a variable fontsize to change the fontsize.To set the fontsize of the table and to ... Read More

Plot a black-and-white binary map in Matplotlib

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 06-May-2021 13:13:17

5K+ Views

To plot black-and-white binary map in matplotlib, we can create and add two subplots to the current figure using subplot() method, where nrows=1 and ncols=2. To display the data as a binary map, we can use greys colormap in imshow() method.StepsCreate data using numpyAdd two sublots, nrows=1 and ncols=2. Consider ... Read More

Advertisements