美文网首页
Matplotlib创建缩放效果

Matplotlib创建缩放效果

作者: overad | 来源:发表于2021-01-30 14:43 被阅读0次
    # -*- coding: utf-8 -*-
    """
    Created on Sat Jan 30 14:14:17 2021
    
    """
    
    # 使用lambda定义函数
    import numpy as np
    import matplotlib.pyplot as plt
    from matplotlib.patches import ConnectionPatch
    
    
    import warnings 
    warnings.filterwarnings('ignore')
    
    stock = lambda A, amp, angle, phase: A * angle + amp * np.sin(angle + phase)
    
    # 定义参数
    theta = np.linspace(0., 2 * np.pi, 250) # x轴
    np.random.seed(100)
    noise = 0.2 * np.random.random(250)
    y = stock(.1, .2, theta, 1.2) + noise # y轴
    
    #创建大小为6*5的主容器
    fig = plt.figure(figsize=(6,5),dpi=144)
    plt.subplots_adjust(bottom=0.,left=0,top=1.,right=1)
    
    #创建第一个轴,左上角的图用绿色的图;
    sub1 = fig.add_subplot(2,2,1)
    sub1.plot(theta,y,color='green')
    sub1.set_xlim(1,2)
    sub1.set_ylim(0.2,.5)
    sub1.set_ylabel('y',labelpad=15)
    
    #创建第二个轴,即左上角的橙色轴;
    sub2 = fig.add_subplot(2,2,2)
    sub2.plot(theta,y,color='orange')
    sub2.set_xlim(5,6)
    sub2.set_ylim(0.4,1)
    
    
    #创建第二个坐标轴
    sub3 = fig.add_subplot(2,2,(3,4))
    sub3.plot(theta,y,color='darkorchid',alpha=.7)
    sub3.set_xlim(0,6.5)
    sub3.set_ylim(0,1)
    
    
    #在第三个轴中创建阻塞区域
    sub3.fill_between((1,2),0,1,facecolor='green',alpha=0.2)
    sub3.fill_between((5,6),0,1,facecolor='orange',alpha=0.2)
    
    #在左侧创建第一个轴的ConnectionPatch
    con1 = ConnectionPatch(xyA=(1,.2),coordsA=sub1.transData,
                           xyB=(1,.3),coordsB=sub3.transData,color='green')
    
    #添加到左侧
    fig.add_artist(con1)
    
    #在右侧创建一个ConnectionPatch
    con2 = ConnectionPatch(xyA=(2,.2),coordsA=sub1.transData,
                            xyB=(2,.3),coordsB=sub3.transData,color='green')
    
    #添加到右侧
    fig.add_artist(con2)
    
    
    #同样创建第二幅的
    con3 = ConnectionPatch(xyA=(5,.4),coordsA=sub2.transData,
                           xyB=(5,.7),coordsB=sub3.transData,color='orange')
    
    fig.add_artist(con3)
    
    con4 = ConnectionPatch(xyA=(6,.4),coordsA=sub2.transData,
                           xyB=(6,.7),coordsB=sub3.transData,color='orange')
    
    fig.add_artist(con4)
    
    plt.show()
    
    Figure 2021-01-30 144121.png

    相关文章

      网友评论

          本文标题:Matplotlib创建缩放效果

          本文链接:https://www.haomeiwen.com/subject/kqakzktx.html