python柱状图的函数 python 柱形图
新手python怎么从Excel中读取多行多列画并列柱状图?
首先,dataframe自带的柱状图,可以将每列作为一个图例
10年积累的成都网站设计、成都网站建设、外贸网站建设经验,可以快速应对客户对网站的新想法和需求。提供各种问题对应的解决方案。让选择我们的客户得到更好、更有力的网络服务。我虽然不认识你,你也不认识我。但先制作网站后付款的网站建设流程,更有临夏免费网站建设让你可以放心的选择与我们合作。
import pandas as pd
data=pd.read_excel()
data.bar()
下面柱状图效果用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怎么用matplotlib画柱状图
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绘制变量vs的柱状图且按照变量gear分组,注意颜色区分?
这边的图的话可以按照那个形状的柱状的那高基来绘制,然后谁的多就绘制的高
Python matplotlib绘制条形柱状图并添加数据标签
最近在学习数据分析,用matplotlit绘制条形图,柱状图老师讲了加标签的方法,但是没有讲横向条形图加数据标签的方法,但是我想到业务场景可能会用到,于是自己写了一个脚本练习一下,用竖向条形图的方法加数据标签,怎么都加不上,百度找到一些解决方法,然后自己改了一下终于解决了这个问题。
重点在这个for循环
当前文章:python柱状图的函数 python 柱形图
浏览路径:http://pwwzsj.com/article/dodhpdp.html