<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                今天晚上學習了下使用pycha模塊來制作各種辦公用圖的方法,非常簡單,本文使用其繪制了7種圖表。 ?此模塊和API地址為:[http://www.lorenzogil.com/projects/pycha/](http://www.lorenzogil.com/projects/pycha/),需要的朋友可以下載下來玩一下,下面是我晚上學習時寫的一點東東,分享之。 ### 一、代碼: ~~~ #!/usr/bin/env python # -*- coding: utf-8 -*- import cairo import pycha.pie import pycha.bar import pycha.scatter import pycha.stackedbar import pycha.line #設置畫布 def set_charvalue(): width,height=600,600 surface=cairo.ImageSurface(cairo.FORMAT_ARGB32,width,height) return surface #畫餅圖 def draw_pie(surface, options, dataSet): chart=pycha.pie.PieChart(surface,options) chart.addDataset(dataSet) chart.render() surface.write_to_png('d:\\Pie.png') #垂直直方圖 def draw_vertical_bar(surface, options, dataSet): chart=pycha.bar.VerticalBarChart(surface,options) chart.addDataset(dataSet) chart.render() surface.write_to_png('d:\\vertical_bar.png') #垂直水平直方圖 def draw_horizontal_bar(surface, options, dataSet): chart = pycha.bar.HorizontalBarChart(surface,options) chart.addDataset(dataSet) chart.render() surface.write_to_png('d:\\horizontal_bar.png') #線圖 def draw_line(surface, options, dataSet): chart = pycha.line.LineChart(surface,options) chart.addDataset(dataSet) chart.render() surface.write_to_png('d:\\line.png') #點圖 def draw_scatterplot(surface, options, dataSet): chart = pycha.scatter.ScatterplotChart(surface,options) chart.addDataset(dataSet) chart.render() surface.write_to_png('d:\\scatterplotChart.png') #垂直塊圖 def draw_stackedverticalbarChar(surface, options, dataSet): chart = pycha.stackedbar.StackedVerticalBarChart(surface,options) chart.addDataset(dataSet) chart.render() surface.write_to_png('d:\\stackedVerticalBarChart.png') #水平塊圖 def draw_stackedhorizontalbarChart(surface, options, dataSet): chart = pycha.stackedbar.StackedHorizontalBarChart(surface,options) chart.addDataset(dataSet) chart.render() surface.write_to_png('d:\\stackedhorizontalbarChart.png') if __name__ == '__main__': ''' Function:使用pycha畫各種圖表 Input:NONE Output: NONE author: socrates blog:http://blog.csdn.net/dyx1024 date:2012-02-28 ''' #數據來源 dataSet=( ('iphone',((0,1),(1,3),(2,2.5))), ('htc',((0,2),(1,4),(2,3))), ('hw',((0,5),(1,1,),(2,0.5))), ('zte',((0,3),(1,2,),(2,1.5))), ) #圖像屬性定義 options={ 'legend':{'hide':False}, 'title':'手機銷售量分布圖(by dyx1024)', 'titleColor':'#0000ff', 'titleFont':'字體', 'background':{'chartColor': '#ffffff'}, 'axis':{'labelColor':'#ff0000'}, } surface = set_charvalue() #根據需要調用不同函數畫不同形狀的圖 #draw_pie(surface, options, dataSet) #draw_vertical_bar(surface, options, dataSet) #draw_horizontal_bar(surface, options, dataSet) #draw_scatterplot(surface, options, dataSet) #draw_stackedverticalbarChar(surface, options, dataSet) #draw_stackedhorizontalbarChart(surface, options, dataSet) draw_line(surface, options, dataSet) ~~~ 二、測試: 1、函數draw_pie(surface, options, dataSet): ![](https://box.kancloud.cn/2016-06-08_5757935654e89.gif) 2、函數draw_vertical_bar(surface, options, dataSet): ![](https://box.kancloud.cn/2016-06-08_575793566fd1f.gif) 3、函數draw_horizontal_bar(surface, options, dataSet): ![](https://box.kancloud.cn/2016-06-08_5757935681e17.gif) 4、函數draw_line(surface, options, dataSet): ![](https://box.kancloud.cn/2016-06-08_575793569d663.gif) 5、函數draw_scatterplot(surface, options, dataSet): ![](https://box.kancloud.cn/2016-06-08_57579356b2992.gif) 6、函數draw_stackedverticalbarChar(surface, options, dataSet): ![](https://box.kancloud.cn/2016-06-08_57579356c4d63.gif) 7、函數draw_stackedhorizontalbarChart(surface, options, dataSet): ![](https://box.kancloud.cn/2016-06-08_57579356d6c16.gif)
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看