Rishikesh Kumar Rishi has Published 1156 Articles

Set variable point size in Matplotlib

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 06-May-2021 12:53:39

432 Views

To set the variable point size in matplotlib, we can take the following steps−Initialize the coordinates of the point.Make a variable to store the point size.Plot the point using scatter method, with marker=o, color=red, s=point_size.To display the figure, use show() method.Examplefrom matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.00, 3.50] ... Read More

How to draw a rectangle over a specific region in a Matplotlib graph?

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 06-May-2021 12:52:30

749 Views

To draw a rectangle over a specific region in a matplotlib graph, we can take the following steps −Using subplots() method, create a figure and a set of subplots, where nrows=1.Using rectangle, we can create a rectangle, defined via an anchor point and its width and height. Where, edgecolor=orange, linewidth=7, and facecolor=green.To ... Read More

How to create a draggable legend in Matplotlib?

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 06-May-2021 12:52:08

2K+ Views

To create a draggable legend in matplotlib, we can take the following steps −Create two lines, line1 and line2, using plot() method.Place the legend for plot line1 and line2 with ordered lables at location 1, using legend() method.To create a draggable legend, use set_draggable() method, where state=True. If state=False, then we can't drag ... Read More

Automatically Rescale ylim and xlim in Matplotlib

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 06-May-2021 12:51:49

2K+ Views

To rescale ylim and xlim automatically, we can take the following steps −To plot a line, use plot() method and data range from 0 to 10.To scale the xlim and ylim automatically, we can make the variable scale_factore=6.Use scale_factor (from Step 2) to rescale the xlim and ylim, using xlim() and ylim() methods, respectively.To display the figure, use ... Read More

How do I plot Shapely polygons and objects using Matplotlib?

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 06-May-2021 12:51:12

6K+ Views

To plot shapely polygons and objects using matplotlib, the steps are as follows −Create a polygon object using (x, y) data points.Get x and y, the exterior data, and the array using polygon.exterior.xy.Plot x and y data points using plot() method with red color.Examplefrom shapely.geometry import Polygon import matplotlib.pyplot as plt ... Read More

How to plot the lines first and points last in Matplotlib?

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 10-Apr-2021 11:40:58

539 Views

To plot the lines first and points last, we can take the following Steps −Create xpoints, y1points and y2points using numpy, to draw lines.Plot the curves using the plot() method with x, y1 and y2 points.Draw the scatter points using the scatter method.To display the figure, use the show() method.Exampleimport ... Read More

How can I create a stacked line graph with matplotlib?

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 10-Apr-2021 08:07:21

1K+ Views

To create a stacked lines graph with Python, we can take the following Steps −Create x, y, y1 and y2 points using numpy.Plot the lines using numpy with the above data (Step 1) and labels mentioned.Fill the color between curve y=e^x and y=0, using the fill_between() method.Fill the color between curve y=2x and ... Read More

How do I change matplotlib's subplot projection of an existing axis?

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 10-Apr-2021 08:04:40

2K+ Views

It seems difficult to change the projection of an existing axis, but we can take the following steps to create different type projections −Using subplot() method, add a subplot to the current figure, with nrows=1, ncols=3 and current index=1.Add a title to the current axis.Using subplot() method, add a subplot ... Read More

Matplotlib Plots Lose Transparency When Saving as .ps/.eps

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 10-Apr-2021 08:01:27

2K+ Views

Whenever plots are saved in .eps/.ps, then the transparency of the plots get lost.To compare them, we can take the following Steps −Create x_data and y_data using numpy.Plot x_data and y_data (Step 1), using the plot() method, with less aplha value, to make it more transparent.Use the grid() method to prove the transparency of ... Read More

How to plot a gradient color line in matplotlib?

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 10-Apr-2021 07:58:32

9K+ Views

To plot a gradient color line in matplotlib, we can take the following steps −Create x, y and c data points, using numpy.Create scatter points over the axes (closely so as to get a line), using the scatter() method with c and marker='_'.To display the figure, use the show() method.Exampleimport ... Read More

Advertisements