In [44]:
'https://matplotlib.org/3.3.0/tutorials/intermediate/artists.html#sphx-glr-tutorials-intermediate-artists-py'

import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(2,1,1)
In [9]:
fig2 = plt.figure()
ax2 = fig2.add_axes([0.15,0.1,0.7,0.3])
In [45]:
import numpy as np
t = np.arange(0.0,1.0,0.01)
s = np.sin(2*np.pi*t)
line, = ax.plot(t,s,color='blue',lw=2)
In [57]:
xtext = ax.set_xlabel('my xdata')
ytext = ax.set_ylabel('my ydata')
In [63]:
import numpy as np
import matplotlib.pyplot as plt

fig = plt.figure()
fig.subplots_adjust(top=0.8)
ax1 = fig.add_subplot(211)
ax1.set_ylabel('volts')
ax1.set_title('a sine wave')

t = np.arange(0,1,0.01)
s = np.sin(2*np.pi*t)
line, = ax1.plot(t,s,color='b',lw=5)

np.random.seed(19680801)

ax2 = fig.add_axes([0.15,0.1,0.7,0.3])
n,bins,patches = ax2.hist(np.random.randn(1000), 50, facecolor='y', edgecolor= 'y')
ax2.set_xlabel('time(s)')

plt.show()
In [97]:
line.set(alpha=0.4,zorder=2,c='#D08080')
Out[97]:
[None, None, None]
In [98]:
fig
Out[98]:
In [102]:
import matplotlib
matplotlib.artist.getp(line)
    agg_filter = None
    alpha = 0.4
    animated = False
    antialiased or aa = True
    children = []
    clip_box = TransformedBbox(     Bbox(x0=0.0, y0=0.0, x1=1.0, ...
    clip_on = True
    clip_path = None
    color or c = #D08080
    contains = None
    dash_capstyle = butt
    dash_joinstyle = round
    data = (array([0.  , 0.01, 0.02, 0.03, 0.04, 0.05, 0.06, ...
    drawstyle or ds = default
    figure = Figure(432x288)
    fillstyle = full
    gid = None
    in_layout = True
    label = _line0
    linestyle or ls = -
    linewidth or lw = 5.0
    marker = None
    markeredgecolor or mec = #D08080
    markeredgewidth or mew = 1.0
    markerfacecolor or mfc = #D08080
    markerfacecoloralt or mfcalt = none
    markersize or ms = 6.0
    markevery = None
    path = Path(array([[ 0.00000000e+00,  0.00000000e+00],   ...
    path_effects = []
    picker = None
    pickradius = 5
    rasterized = None
    sketch_params = None
    snap = None
    solid_capstyle = projecting
    solid_joinstyle = round
    transform = CompositeGenericTransform(     TransformWrapper(  ...
    transformed_clip_path_and_affine = (None, None)
    url = None
    visible = True
    xdata = [0.   0.01 0.02 0.03 0.04 0.05]...
    xydata = [[0.         0.        ]  [0.01       0.06279052] ...
    ydata = [0.         0.06279052 0.12533323 0.18738131 0.248...
    zorder = 2
In [125]:
fig = plt.figure()

ax1 = fig.add_subplot(211)
ax2 = fig.add_axes([0.1,0.1,0.7,0.3])
In [129]:
for ax in fig.axes:
    ax.grid(True)
fig
Out[129]:
In [207]:
?Legend
In [222]:
import matplotlib.lines as lines
from matplotlib.patches import Rectangle
from matplotlib.legend import Legend

fig = plt.figure()

l1 = lines.Line2D([0,1],[0,1],transform = fig.transFigure,figure=fig)
l2 = lines.Line2D([0, 1], [1, 0],  figure=fig,transform=fig.transFigure)
r1 = Rectangle((0.5,0.5),0.4,0.4,color='r',figure=fig,transform=fig.transFigure)

fig.lines.extend([l1,l2])
fig.patches.append(r1)

plt.show()
In [223]:
ax = fig.add_subplot(111)
rect = ax.patch
rect.set_facecolor('g')
fig
Out[223]:
In [248]:
x,y = np.random.rand(2,100)
line, = ax.plot(x, y, '-', color='b', lw=2)

n,bins,rectangles = ax.hist(np.random.randn(1000),50)
print(len(ax.patches))
1100
In [249]:
fig, ax = plt.subplots()

# create a rectangle instance
rect = matplotlib.patches.Rectangle((1, 1), width=5, height=12)

# by default the axes instance is None
print(rect.axes)


# and the transformation instance is set to the "identity transform"
print(rect.get_transform())

# now we add the Rectangle to the Axes
ax.add_patch(rect)

# and notice that the ax.add_patch method has set the axes
# instance
print(rect.axes)

# and the transformation has been set too
print(rect.get_transform())

# the default axes transformation is ax.transData
print(ax.transData)

# notice that the xlimits of the Axes have not been changed
print(ax.get_xlim())

# but the data limits have been updated to encompass the rectangle
print(ax.dataLim.bounds)

# we can manually invoke the auto-scaling machinery
ax.autoscale_view()

# and now the xlim are updated to encompass the rectangle
print(ax.get_xlim())

# we have to manually force a figure draw
ax.figure.canvas.draw()
None
CompositeGenericTransform(
    BboxTransformTo(
        Bbox(x0=1.0, y0=1.0, x1=6.0, y1=13.0)),
    Affine2D(
        [[1. 0. 0.]
         [0. 1. 0.]
         [0. 0. 1.]]))
AxesSubplot(0.125,0.125;0.775x0.755)
CompositeGenericTransform(
    CompositeGenericTransform(
        BboxTransformTo(
            Bbox(x0=1.0, y0=1.0, x1=6.0, y1=13.0)),
        Affine2D(
            [[1. 0. 0.]
             [0. 1. 0.]
             [0. 0. 1.]])),
    CompositeGenericTransform(
        TransformWrapper(
            BlendedAffine2D(
                IdentityTransform(),
                IdentityTransform())),
        CompositeGenericTransform(
            BboxTransformFrom(
                TransformedBbox(
                    Bbox(x0=0.0, y0=0.0, x1=1.0, y1=1.0),
                    TransformWrapper(
                        BlendedAffine2D(
                            IdentityTransform(),
                            IdentityTransform())))),
            BboxTransformTo(
                TransformedBbox(
                    Bbox(x0=0.125, y0=0.125, x1=0.9, y1=0.88),
                    BboxTransformTo(
                        TransformedBbox(
                            Bbox(x0=0.0, y0=0.0, x1=6.0, y1=4.0),
                            Affine2D(
                                [[72.  0.  0.]
                                 [ 0. 72.  0.]
                                 [ 0.  0.  1.]]))))))))
CompositeGenericTransform(
    TransformWrapper(
        BlendedAffine2D(
            IdentityTransform(),
            IdentityTransform())),
    CompositeGenericTransform(
        BboxTransformFrom(
            TransformedBbox(
                Bbox(x0=0.0, y0=0.0, x1=1.0, y1=1.0),
                TransformWrapper(
                    BlendedAffine2D(
                        IdentityTransform(),
                        IdentityTransform())))),
        BboxTransformTo(
            TransformedBbox(
                Bbox(x0=0.125, y0=0.125, x1=0.9, y1=0.88),
                BboxTransformTo(
                    TransformedBbox(
                        Bbox(x0=0.0, y0=0.0, x1=6.0, y1=4.0),
                        Affine2D(
                            [[72.  0.  0.]
                             [ 0. 72.  0.]
                             [ 0.  0.  1.]])))))))
(0.0, 1.0)
(1.0, 1.0, 5.0, 12.0)
(0.75, 6.25)
In [250]:
for label in ax.get_xticklabels():
    label.set_color('orange')