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——使用matplotlib繪制柱狀圖
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的Pandas庫可以繪制很多圖形,那么如何繪制柱形圖呢?下面我給大家分享演示一下。
工具/材料
Pycharm
01
首先我們打開Excel文件,準備要生成柱形圖的數據表,如下圖所示
02
接下來在Python文件中導入pandas庫,然后將Excel文件加載到緩存對象中,如下圖所示
03
然后我們導入matplotlib下面的pyplot庫,如下圖所示,導入以后給它起一個別名
04
接下來我們通過pandas庫下面的bar來設置柱形圖的X,Y坐標軸,如下圖所示
05
然后通過pyplot的show方法將柱形圖進行展示出來,如下圖所示
06
接下來運行程序以后我們就看到柱形圖生成出來了,如下圖所示
07
然后如果我們想將柱形圖中的數據排序的話可以利用sort_values實現,如下圖所示
08
最后運行排序好后的程序,我們就可以看到柱形圖中的數據已經排序好了,如下圖所示
新聞名稱:柱狀圖的函數python,柱狀圖曲線
瀏覽路徑:http://vcdvsql.cn/article34/hchise.html
成都網站建設公司_創新互聯,為您提供營銷型網站建設、網站制作、搜索引擎優化、用戶體驗、網站維護、網頁設計公司
聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯