最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Python使用pylab庫實現(xiàn)畫線功能的方法詳解

 更新時間:2017年06月08日 09:24:28   作者:糖拌咸魚  
這篇文章主要介紹了Python使用pylab庫實現(xiàn)畫線功能的方法,結(jié)合具體實例分析了Python使用pylab庫的相關(guān)函數(shù)實現(xiàn)畫線功能的操作技巧,并附帶說明了相關(guān)函數(shù)與參數(shù)功能,需要的朋友可以參考下

本文實例講述了Python使用pylab庫實現(xiàn)畫線功能的方法。分享給大家供大家參考,具體如下:

pylab 提供了比較強大的畫圖功能,但是函數(shù)和參數(shù)都比較多,很容易搞混。我們平常使用最多的應(yīng)該是畫線了。下面,簡單的對一些常用的劃線函數(shù)進(jìn)行了封裝,方便使用。

# -*- coding: utf-8 -*-
import pylab
import random
class MiniPlotTool :
  '''
  A mini tool to draw lines using pylab
  '''
  basecolors = ['red','green','yellow','blue','black','cyan','magenta']
  def __init__(self, baseConfig) :
    self.figsize = baseConfig.get('figsize',None)
    self.axis = baseConfig.get('axis',None)
    self.title = baseConfig.get('title','NoName')
    self.ylabel = baseConfig.get('ylabel','NoName')
    self.grid = baseConfig.get('grid',False)
    self.xaxis_locator = baseConfig.get('xaxis_locator',None)
    self.yaxis_locator = baseConfig.get('yaxis_locator',None)
    self.legend_loc = baseConfig.get('legend_loc',0)
    if self.figsize != None :
      pylab.figure(figsize = self.figsize)
    if self.axis != None :
      pylab.axis(self.axis)
    pylab.title(self.title)
    pylab.ylabel(self.ylabel)
    ax = pylab.gca()
    pylab.grid(self.grid)
    if self.xaxis_locator != None :
      ax.xaxis.set_major_locator( pylab.MultipleLocator(self.xaxis_locator) )
    if self.yaxis_locator != None :
      ax.yaxis.set_major_locator( pylab.MultipleLocator(self.yaxis_locator) )
    self.lineList = []
    self.id = 1
  def addline(self, lineConf) :
    self.lineList.append((self.id, lineConf))
    self.id += 1
    return {'id' : self.id - 1}
  def removeline(self, lineId) :
    for i in range(len(self.lineList)) :
      id, conf = self.lineList[i]
      if id == lineId :
        del self.lineList[i]
        break
    else :
      return {'status' : -1}
    print len(self.lineList)
    return {'status' : 0}
  def __parselineConf(self, lineConf) :
    X = lineConf['X']
    Y = lineConf['Y']
    marker = lineConf.get('marker',None)
    color = lineConf.get('color', random.choice(MiniPlotTool.basecolors))
    markerfacecolor = lineConf.get('markerfacecolor',color)
    label = lineConf.get('label','NoName')
    linewidth = lineConf.get('linewidth',1)
    linestyle = lineConf.get('linestyle','-')
    return X, Y, marker, color, markerfacecolor, label, linewidth, linestyle
  def plotSingleLine(self, lineConf):
    X, Y, marker, color, markerfacecolor, label, linewidth, linestyle = self.__parselineConf(lineConf)
    pylab.plot(X, Y, marker = marker, color = color, markerfacecolor = markerfacecolor, label=label, linewidth = linewidth, linestyle = linestyle)
    pylab.legend(loc = self.legend_loc)
  def plot(self) :
    colors = [MiniPlotTool.basecolors[i % len(MiniPlotTool.basecolors)] for i in range(len(self.lineList))]
    for i in range(len(self.lineList)) :
      id, conf = self.lineList[i]
      if conf.get('color',None) :
        conf['color'] = colors[i]
      X, Y, marker, color, markerfacecolor, label, linewidth, linestyle = self.__parselineConf(conf)
      pylab.plot(X, Y, marker = marker, color = color, markerfacecolor = markerfacecolor, label=label, linewidth = linewidth, linestyle = linestyle)
    pylab.legend(loc = self.legend_loc)
  def show(self) :
    pylab.show()
if __name__ == '__main__' :
  #test
  baseConfig = {
    #'figsize' : (6,8),
    #'axis': [0,10,0,10],
    #'title' : 'hello title',
    #'ylabel' : 'hello ylabel',
    'grid' : True,
    #'xaxis_locator' : 0.5,
    #'yaxis_locator' : 1,
    #'legend_loc' : 'upper right'
  }
  tool = MiniPlotTool(baseConfig)
  X = [ i for i in range(10)]
  Y = [random.randint(1,10) for i in range(10)]
  Y2 = [random.randint(1,10) for i in range(10)]
  lineConf = {
    'X' : X,
    'Y' : Y
    #'marker' : 'x',
    #'color' : 'b',
    #'markerfacecolor' : 'r',
    #'label' : '222',
    #'linewidth' : 3,
    #'linestyle' : '--'
  }
  lineConf2 = {
    'X' : X,
    'Y' : Y2,
    'marker' : 'o',
    'color' : 'b',
    'markerfacecolor' : 'r',
    'label' : '222',
    'linewidth' : 3,
    'linestyle' : '--'
  }
  #tool.plotSingleLine(lineConf)
  print tool.addline(lineConf)
  print tool.addline(lineConf2)
  #print tool.removeline(1)
  tool.plot()
  tool.show()

運行效果圖如下:

附:引用自:https://sites.google.com/site/guyingbo/matplotlib%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0

線屬性:

顏色(color 簡寫為 c):

藍(lán)色: 'b' (blue)
綠色: 'g' (green)
紅色: 'r' (red)
藍(lán)綠色(墨綠色): 'c' (cyan)
紅紫色(洋紅): 'm' (magenta)
黃色: 'y' (yellow)
黑色: 'k' (black)
白色: 'w' (white)
灰度表示: e.g. 0.75 ([0,1]內(nèi)任意浮點數(shù))
RGB表示法: e.g. '#2F4F4F' 或 (0.18, 0.31, 0.31)
任意合法的html中的顏色表示: e.g. 'red', 'darkslategray'
線型(linestyle 簡寫為 ls):

實線: '-'
虛線: '--'
虛點線: '-.'
點線: ':'
點: '.'
點型(標(biāo)記marker):

像素: ','
圓形: 'o'
上三角: '^'
下三角: 'v'
左三角: '<'
右三角: '>'
方形: 's'
加號: '+'
叉形: 'x'
棱形: 'D'
細(xì)棱形: 'd'
三腳架朝下: '1'(就是丫)
三腳架朝上: '2'
三腳架朝左: '3'
三腳架朝右: '4'
六角形: 'h'
旋轉(zhuǎn)六角形: 'H'
五角形: 'p'
垂直線: '|'
水平線: '_'
gnuplot 中的steps: 'steps' (只能用于kwarg中)
標(biāo)記大?。╩arkersize 簡寫為 ms):

markersize: 實數(shù)
標(biāo)記邊緣寬度(markeredgewidth 簡寫為 mew):

markeredgewidth:實數(shù)
標(biāo)記邊緣顏色(markeredgecolor 簡寫為 mec):

markeredgecolor:顏色選項中的任意值
標(biāo)記表面顏色(markerfacecolor 簡寫為 mfc):

markerfacecolor:顏色選項中的任意值
透明度(alpha):

alpha: [0,1]之間的浮點數(shù)
線寬(linewidth):

linewidth: 實數(shù)

更多關(guān)于Python相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Python圖片操作技巧總結(jié)》、《Python數(shù)據(jù)結(jié)構(gòu)與算法教程》、《Python函數(shù)使用技巧總結(jié)》、《Python字符串操作技巧匯總》、《Python入門與進(jìn)階經(jīng)典教程》及《Python文件與目錄操作技巧匯總

希望本文所述對大家Python程序設(shè)計有所幫助。

相關(guān)文章

最新評論

女性| 泸西县| 上蔡县| 乐昌市| 永春县| 道真| 米易县| 辽宁省| 资阳市| 讷河市| 上思县| 嘉鱼县| 安龙县| 达尔| 滨州市| 北海市| 禹州市| 澎湖县| 安丘市| 五大连池市| 南投市| 南京市| 阿拉善右旗| 建湖县| 若尔盖县| 通州区| 甘德县| 赞皇县| 定西市| 卢氏县| 密云县| 临邑县| 望奎县| 西安市| 驻马店市| 出国| 武穴市| 色达县| 根河市| 高安市| 南部县|