下面柱状图效果用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 rot>360

%     rot=rot-360;

% end

% while rot<0

%     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 rot<180

    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)


%满意请采纳

温馨提示:答案为网友推荐,仅供参考
第1个回答  2018-11-16

# -*- coding: utf-8 -*-
"""
Created on Fri Nov 16 11:10:01 2018
@author: mayongdong
"""
import numpy as np
import matplotlib.pyplot as plt

name_list = ['lanmu1','lanmu2','lanmu3','lanmu4','lanmu5','lanmu6']
num_list = [795,583,366,260,155,80]

fig, axs = plt.subplots(2)
fig.subplots_adjust(hspace=0.75)
axs[0].bar(name_list,num_list)
axs[1].bar(name_list,num_list)

for label in axs[0].get_xmajorticklabels() + axs[1].get_xmajorticklabels():
label.set_rotation(30)
label.set_horizontalalignment("right")

希望帮助到你!

第2个回答  2016-09-13
我用易语言能做出来,这英文看不懂追问

易语言就算了,我不会。我还要画好几张图

追答

你是用软件做

这个简单

用平时办公软件 可以做的

相似回答