重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
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
最后运行排序好后的程序,我们就可以看到柱形图中的数据已经排序好了,如下图所示