python画图

#coding=utf-8
import matplotlib.pyplot as plt
import numpy as np
nonLeafNode=dict(boxstyle="sawtooth",fc="0.8")  #非叶节点,箱子格式,和
leafNodes=dict(boxstyle="round4",fc="0.8")
line=dict(arrowstyle="<-")



def plotNode(nodeName,targetPt,parentPt,nodeType):

    """
pyplot.annotate(s,xy, xytext=None, xycoords=’data’,textcoords=’data’, arrowprops=None, **kwargs)
    s=nodeName='nonLeafNode'      //是annotate的文本解释,是注解内容。
    xy=parentPt=(0.4,0.8)          //为点的坐标
    xycoords='axes fraction' 和textcoords='axes fraction'      //是坐标xy和xytext的说明,
                   若textcoords=None,则默认textNone与xycoords相同,若都未设置,默认为data
            'figure points'     //xy将以图片像素源点开始,也就是左下点
            'figure pixels'     //xy将以图片坐标轴为起点,也是左下的
            'figure fraction'   //图片的相对位置坐标xy(0.4,0.8)
            'axes points'       //子图坐标轴的源点
            'axes pixels'       //子图坐标轴的起点
            'axes fraction'     //坐标中的相对位置
            'data'              use the coordinate system of the object being
                            annotated (default)  //默认,也就是数据点 xy=parentPt=(0.4,0.8)
    

    
    xytext=targetPt=(0.2,0.1)      //为注解内容位置坐标,当该值为None时,注解内容放在xy处。
    arrowprops=line=dict(arrowstyle="<-")    //用于设置字典的形状,类型为字典类型。
    **kwargs        //用于接收其他设置参数,比如bbox用于设置文本的边框形状
    va="center"     //居中,可以不写。
    """
    createPlot.ax1.annotate(nodeName,xy=parentPt,xycoords='data',xytext=targetPt,textcoords='axes fraction',\
                            bbox=nodeType,arrowprops=line)
def createPlot():
    """
    plt.figure()//对图片的设置。
    figure(num=None, figsize=None, dpi=None, facecolor=None, edgecolor=None, frameon=True, FigureClass=<class 'matplotlib.figure.Figure'>, **kwargs)
    num    //图片编号
    figsize  //是一个整数型元组,指定图片的宽和高
    dpi      //图片像素精度。
    facecolor   //背景颜色
    edgecolor    //边界颜色
    返回一个Figure对象。也就是返回一张图片。

    """
    
    fig=plt.figure(2,dpi=1,facecolor='white')   #图片
    fig.clf()  #清空图片
    createPlot.ax1=plt.subplot(111,frameon=False)   #plt.subplot()相当于还是plot类型,就像节点的子节点还是节点。
    plotNode('nonLeafNode',(0.2,0.1),(0.4,0.8),nonLeafNode)  #(0.4,0.8)  #相当于坐标,'nonLeafNode'标记。nonLeafNode 用于设置文本的边框形状
    plotNode('leafNodes',(0.8,0.1),(0.6,0.8),leafNodes)
    plt.show()

createPlot()

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值