1. <ul id="0c1fb"></ul>

      <noscript id="0c1fb"><video id="0c1fb"></video></noscript>
      <noscript id="0c1fb"><listing id="0c1fb"><thead id="0c1fb"></thead></listing></noscript>

      99热在线精品一区二区三区_国产伦精品一区二区三区女破破_亚洲一区二区三区无码_精品国产欧美日韩另类一区

      RELATEED CONSULTING
      相關咨詢
      選擇下列產品馬上在線溝通
      服務時間:8:30-17:00
      你可能遇到了下面的問題
      關閉右側工具欄

      新聞中心

      這里有您想知道的互聯網營銷解決方案
      柱狀圖函數python python柱狀圖圖例

      python怎么用matplotlib畫柱狀圖

      Python——使用matplotlib繪制柱狀圖

      創(chuàng)新互聯公司專注于振安網站建設服務及定制,我們擁有豐富的企業(yè)做網站經驗。 熱誠為您提供振安營銷型網站建設,振安網站制作、振安網頁設計、振安網站官網定制、微信小程序開發(fā)服務,打造振安網絡公司原創(chuàng)品牌,更為您提供振安網站排名全網營銷落地服務。

      1、基本柱狀圖

      首先要安裝matplotlib 可以使用pip命令直接安裝

      [python]?view plain?copy

      #?-*-?coding:?utf-8?-*-

      import?matplotlib.pyplot?as?plt

      num_list?=?[1.5,0.6,7.8,6]

      plt.bar(range(len(num_list)),?num_list)

      plt.show()

      2、設置顏色

      [python]?view plain?copy

      #?-*-?coding:?utf-8?-*-

      import?matplotlib.pyplot?as?plt

      num_list?=?[1.5,0.6,7.8,6]

      plt.bar(range(len(num_list)),?num_list,fc='r')

      plt.show()

      [cpp]?view plain?copy

      #?-*-?coding:?utf-8?-*-

      import?matplotlib.pyplot?as?plt

      num_list?=?[1.5,0.6,7.8,6]

      plt.bar(range(len(num_list)),?num_list,color='rgb')

      plt.show()

      3、設置標簽

      [python]?view plain?copy

      #?-*-?coding:?utf-8?-*-

      import?matplotlib.pyplot?as?plt

      name_list?=?['Monday','Tuesday','Friday','Sunday']

      num_list?=?[1.5,0.6,7.8,6]

      plt.bar(range(len(num_list)),?num_list,color='rgb',tick_label=name_list)

      plt.show()

      4、堆疊柱狀圖

      求助,python畫柱狀圖,如何在里面填充不同圖案

      bar函數調用中添加輸入參數hatch,例子如下:

      import?matplotlib.pyplot?as?plt

      x1_value=1

      y1_value=10

      x2_value=2

      y2_value=20

      bar_width?=?0.2

      plt.bar(x1_value,?y1_value,?bar_width,?hatch='*')

      plt.bar(x2_value,?y2_value,?bar_width,?hatch='/')

      picName='test.png'

      plt.savefig(output_path?+?picName,?dpi=200)

      結果:

      關于hatch值的填法,可參考:

      下面柱狀圖效果用python怎么做出來?主要是橫坐標的變量名要斜著寫這種方式。matlab也行

      matlab實現演示效果如下:

      %需要新建一個function,以下是function的代碼(保存時文件名只能是rotateticklabel.m):

      function th=rotateticklabel(h,rot,demo)

      %ROTATETICKLABEL rotates tick labels

      % ? TH=ROTATETICKLABEL(H,ROT) ris the calling form where H is a handle to

      % ? the axis that contains the XTickLabels that are to be rotated. ROT is

      % ? an optional parameter that specifies the angle of rotation. The default

      % ? angle is 90. TH is a handle to the text objects created. For long

      % ? strings such as those produced by datetick, you may have to adjust the

      % ? position of the axes so the labels don't get cut off.

      %

      % ? Of course, GCA can be substituted for H if desired.

      %

      % ? TH=ROTATETICKLABEL([],[],'demo') shows a demo figure.

      %

      % ? Known deficiencies: if tick labels are raised to a power, the power

      % ? will be lost after rotation.

      %

      % ? See also datetick.

      % ? Written Oct 14, 2005 by Andy Bliss

      % ? Copyright 2005 by Andy Bliss

      %DEMO:

      if nargin==3

      x=[now-.7 now-.3 now];

      y=[20 35 15];

      figure

      plot(x,y,'.-')

      datetick('x',0,'keepticks')

      h=gca;

      set(h,'position',[0.13 0.35 0.775 0.55])

      rot=90;

      end

      %set the default rotation if user doesn't specify

      if nargin==1

      rot=90;

      end

      %make sure the rotation is in the range

      % 0:360 (brute force method)

      % while rot360

      % ? ? rot=rot-360;

      % end

      % while rot0

      % ? ? rot=rot+360;

      % end

      %get current tick labels

      a=get(h,'XTickLabel');

      %erase current tick labels from figure

      set(h,'XTickLabel',[]);

      %get tick label positions

      b=get(h,'XTick');

      c=get(h,'YTick');

      %make new tick labels

      if rot180

      th=text(b,repmat(c(1)-.1*(c(2)-c(1)),length(b),1),a,'HorizontalAlignment','right','fontsize',14,'fontweight','bold','rotation',rot);

      else

      th=text(b,repmat(c(1)-.1*(c(2)-c(1)),length(b),1),a,'HorizontalAlignment','left','fontsize',14,'fontweight','bold','rotation',rot);

      end

      %畫好圖需要旋轉坐標時調用上面的rotateticklabel函數,比如用以下的測試數據

      x = round(rand(5,3)*10);

      h=bar(x,1,'group');

      set(gca,'xticklabels',{'benchmark1','benchmark2','benchmark3','benchmark4','benchmark5'});

      h = gca;

      th=rotateticklabel(h, 45)

      %滿意請采納


      當前名稱:柱狀圖函數python python柱狀圖圖例
      網頁鏈接:http://www.ef60e0e.cn/article/doscpjh.html
      99热在线精品一区二区三区_国产伦精品一区二区三区女破破_亚洲一区二区三区无码_精品国产欧美日韩另类一区
      1. <ul id="0c1fb"></ul>

        <noscript id="0c1fb"><video id="0c1fb"></video></noscript>
        <noscript id="0c1fb"><listing id="0c1fb"><thead id="0c1fb"></thead></listing></noscript>

        浮山县| 昌黎县| 大余县| 泸西县| 青田县| 丹寨县| 东乡县| 东明县| 壶关县| 安康市| 巨野县| 宣恩县| 衡山县| 梓潼县| 铜陵市| 平南县| 赣州市| 阿合奇县| 阳泉市| 罗城| 扎鲁特旗| 新乐市| 澄城县| 商河县| 淄博市| 宜州市| 吴旗县| 吉水县| 昌邑市| 南陵县| 牙克石市| 桦南县| 绩溪县| 南投市| 金平| 墨玉县| 宁武县| 昌吉市| 泗阳县| 林口县| 志丹县|