Skip to content
Related Articles

Related Articles

Matplotlib.figure.Figure.gca() in Python
  • Last Updated : 30 Apr, 2020

Matplotlib is a library in Python and it is numerical – mathematical extension for NumPy library. The figure module provides the top-level Artist, the Figure, which contains all the plot elements. This module is used to control the default spacing of the subplots and top level container for all plot elements.

matplotlib.figure.Figure.gca() method

The gca() method figure module of matplotlib library is used to get the current axes.

Syntax: gca(self, **kwargs)

Parameters: This method does not accept any parameters.

Returns: This method returns the current axes.

Below examples illustrate the matplotlib.figure.Figure.gca() function in matplotlib.figure:

Example 1:

# Implementation of matplotlib function
import matplotlib.pyplot as plt
import numpy as np
import matplotlib.gridspec as gridspec
from mpl_toolkits.axes_grid1 import make_axes_locatable
arr = np.arange(100).reshape((10, 10))
fig = plt.figure(figsize =(4, 4))
im = plt.imshow(arr,
                interpolation ="none",
                cmap ="plasma")
divider = make_axes_locatable(fig.gca())
cax = divider.append_axes("left",
                          "15 %"
                           pad ="30 %")
plt.colorbar(im, cax = cax)
 function Example', fontweight ="bold"


Example 2:

#Implementation of matplotlib function
import matplotlib.pyplot as plt
from matplotlib.tri import Triangulation
from matplotlib.patches import Polygon
import numpy as np
ang = 3
radi = 8
radii = np.linspace(0.25, 0.95, radi)
res = np.linspace(0, 4 * np.pi, ang)
res = np.repeat(res[..., np.newaxis], radi, axis=1)
res[:, 1::2] += np.pi / ang
x = (radii*np.cos(2*res)).flatten()
y = (radii*np.sin(2*res)).flatten()
triang = Triangulation(x, y)
                < 0.25)
trifinder = triang.get_trifinder()
fig = plt.figure()
plt.triplot(triang, 'go-')
polygon = Polygon([[0, 0], [0, 0]], facecolor='r')
def update_polygon(tri):
    if tri == -1:
        points = [0, 0, 0]
        points = triang.triangles[tri]
    xs = triang.x[points]
    ys = triang.y[points]
    polygon.set_xy(np.column_stack([xs, ys]))
def motion_notify(event):
    if event.inaxes is None:
        tri = -1
        tri = trifinder(event.xdata, event.ydata)
    function Example\n\n Potion number : %i' % tri,


 Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.  

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course

My Personal Notes arrow_drop_up
Recommended Articles
Page :