这是我用来比较两个具有随机均值和标准偏差的组的示例代码。但是,我想在框图中的一个框中绘制两个组,如附件图所示,其中X轴为第1组,Y轴是第2组。我找不到任何执行此操作的代码。有人可以帮我吗?
clc clear x=[rand(1,10) rand(1,10) rand(1,10) rand(1,10) rand(1,10) rand(1,10)]; n=10 ; xx=([1:6])'; % example r=repmat(xx,1,n)'; g=r(:)'; positions = [1 2 3 4 5 6 ]; h=boxplot(x,g, 'positions', positions); set(h,'linewidth',2) set(gca,'xtick',[mean(positions(1:2)) mean(positions(3:4)) mean(positions(5:6)) ]) set(gca,'xticklabel',{'exp1','exp2','exp3'},'Fontsize',28) color = ['c', 'y', 'c', 'y','c', 'y']; h = findobj(gca,'Tag','Box'); for j=1:length(h) patch(get(h(j),'XData'),get(h(j),'YData'),color(j),'FaceAlpha',.5); end 现在,我要在一个盒子中使用黄色和蓝色的exp1。
对于单个双面箱形图,我们可以使用 'Orientation' 属性和覆盖2个盒子图一个上方:
x = [1 2 3 4 5 6 7 1 2 3 4 5 6 7];group = [1,1,1,1,1,1,1,2,2,2,2,2,2,2];% we need the precntiles of the groups so the boxes will overlap.% on each boxplot we set the width to the other boxplot hight:p1 = prctile(x(group==1),[25 75]);p2 = prctile(x(group==2),[25 75]);ax = axes;% first group is vertical:boxplot(x(group==2),'Positions',mean(x(group==1)),... 'Orientation','vertical','Widths',p1(2)-p1(1),'Colors','r');lims1 = axis;hold on% secound group is horizontal:boxplot(x(group==1),'Positions',mean(x(group==2)),... 'Orientation','horizontal','Widths',p2(2)-p2(1),'Colors','k');% the values of the axis are no longer relevant, since they have two% different meanings, depend on the group. So we hide them.ax.XAxis.Visible = 'off';ax.YAxis.Visible = 'off';hold offlims2 = axis;% because each axis represent to different things, we make sure we see% everything:axis([max(lims1(1),lims2(1)),... min(lims1(2),lims2(2)),... min(lims1(3),lims2(3)),... max(lims1(4),lims2(4))])要创建多个双面盒子图,您需要为每个实验使用轴:
x = rand(10,6); nsp = floor(size(x,2)/2); % the number of subplotsmeanx = mean(x);% we need the precntiles of the groups so the boxes will overlap.% on each boxplot we set the width to the other boxplot hight:width = range(prctile(x,[25; 75]));main_ax = axes; % create a tmporary axes% we get the measurements of the ploting area:pos = main_ax.Position;% and divide it to our data:axwidth = pos(3)/nsp; % the width of each group% the bottom left corner of each group:corner = linspace(pos(1),pos(3)+pos(1),nsp+1);clf % clear the area!% now we plot each pair of boxplot on a different subplot:for k = 1:2:size(x,2) ax = axes('Position',[corner((k+1)/2) pos(2) axwidth pos(4)]); hold on % first group is vertical: boxplot(x(:,k),'Positions',meanx(k+1),... 'Orientation','vertical','Widths',width(k+1),'Colors','r'); % secound group is horizontal: boxplot(x(:,k+1),'Positions',meanx(k),... 'Orientation','horizontal','Widths',width(k),'Colors','k'); % the values of the y-axis are no longer relevant, since they have two % different meanings, depend on the group. So we hide them. ax.YAxis.Visible = 'off'; % we use the x-axis to label the pairs of boxplots: ax.XAxis.TickLabels = ['Exp ' num2str((k+1)/2)]; % because each axis represent to different things, we make sure we see % everything: minx = min(min(x(:,k:k+1)))*0.1; maxx = max(max(x(:,k:k+1)))*1.1; axis ([minx maxx minx maxx]) hold off box off % set the locations to the exact same place: bx = findobj(ax,'tag','Box'); % get the boxes posXdif = bx(2).XData(1)-bx(1).XData(1); % get the horizontal difference posYdif = bx(2).YData(1)-bx(1).YData(1); % get the vertical difference bx2Xdata = get(ax.Children(2).Children,{'XData'}); % get all X-data of box 2 bx2Ydata = get(ax.Children(2).Children,{'YData'}); % get all Y-data of box 2 % substruct horizontal difference X-data: set(ax.Children(2).Children,{'XData'},... cellfun(@(x) x-posXdif,bx2Xdata,'UniformOutput',false)) % substruct vertical difference Y-data: set(ax.Children(2).Children,{'YData'},... cellfun(@(y) y-posYdif,bx2Ydata,'UniformOutput',false))endRails2.3可以选择随时使用RouteSet#add_configuration_file添加更多路由。是否可以在Rails3项目中做同样的事情? 最佳答案 在config/application.rb中:config.paths.config.routes在Rails3.2(也可能是Rails3.1)中,使用:config.paths["config/routes"] 关于ruby-on-rails-Rails3中的多个路由文件,我们在StackOverflow上找到一个类似的问题
我有多个ActiveRecord子类Item的实例数组,我需要根据最早的事件循环打印。在这种情况下,我需要打印付款和维护日期,如下所示:ItemAmaintenancerequiredin5daysItemBpaymentrequiredin6daysItemApaymentrequiredin7daysItemBmaintenancerequiredin8days我目前有两个查询,用于查找maintenance和payment项目(非排他性查询),并输出如下内容:paymentrequiredin...maintenancerequiredin...有什么方法可以改善上述(丑陋的)代
我需要从一个View访问多个模型。以前,我的links_controller仅用于提供以不同方式排序的链接资源。现在我想包括一个部分(我假设)显示按分数排序的顶级用户(@users=User.all.sort_by(&:score))我知道我可以将此代码插入每个链接操作并从View访问它,但这似乎不是“ruby方式”,我将需要在不久的将来访问更多模型。这可能会变得很脏,是否有针对这种情况的任何技术?注意事项:我认为我的应用程序正朝着单一格式和动态页面内容的方向发展,本质上是一个典型的网络应用程序。我知道before_filter但考虑到我希望应用程序进入的方向,这似乎很麻烦。最终从任何
我有一个围绕一些对象的包装类,我想将这些对象用作散列中的键。包装对象和解包装对象应映射到相同的键。一个简单的例子是这样的:classAattr_reader:xdefinitialize(inner)@inner=innerenddefx;@inner.x;enddef==(other)@inner.x==other.xendenda=A.new(o)#oisjustanyobjectthatallowso.xb=A.new(o)h={a=>5}ph[a]#5ph[b]#nil,shouldbe5ph[o]#nil,shouldbe5我试过==、===、eq?并散列所有无济于事。
我有一个具有一些属性的模型:attr1、attr2和attr3。我需要在不执行回调和验证的情况下更新此属性。我找到了update_column方法,但我想同时更新三个属性。我需要这样的东西:update_columns({attr1:val1,attr2:val2,attr3:val3})代替update_column(attr1,val1)update_column(attr2,val2)update_column(attr3,val3) 最佳答案 您可以使用update_columns(attr1:val1,attr2:val2
我正在尝试修改当前依赖于定义为activeresource的gem:s.add_dependency"activeresource","~>3.0"为了让gem与Rails4一起工作,我需要扩展依赖关系以与activeresource的版本3或4一起工作。我不想简单地添加以下内容,因为它可能会在以后引起问题:s.add_dependency"activeresource",">=3.0"有没有办法指定可接受版本的列表?~>3.0还是~>4.0? 最佳答案 根据thedocumentation,如果你想要3到4之间的所有版本,你可以这
我正在尝试按0-9和a-z的顺序创建数字和字母列表。我有一组值value_array=['0','1','2','3','4','5','6','7','8','9','a','b','光盘','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','','u','v','w','x','y','z']和一个组合列表的数组,按顺序,这些数字可以产生x个字符,比方说三个list_array=[]和一个当前字母和数字组合的数组(在将它插入列表数组之前我会把它变成一个字符串,]current_combo['0','0','0']
是否有可能:before_filter:authenticate_user!||:authenticate_admin! 最佳答案 before_filter:do_authenticationdefdo_authenticationauthenticate_user!||authenticate_admin!end 关于ruby-on-rails-before_filter运行多个方法,我们在StackOverflow上找到一个类似的问题: https://
我正在使用Rails3.1并在一个论坛上工作。我有一个名为Topic的模型,每个模型都有许多Post。当用户创建新主题时,他们也应该创建第一个Post。但是,我不确定如何以相同的形式执行此操作。这是我的代码:classTopic:destroyaccepts_nested_attributes_for:postsvalidates_presence_of:titleendclassPost...但这似乎不起作用。有什么想法吗?谢谢! 最佳答案 @Pablo的回答似乎有你需要的一切。但更具体地说...首先改变你View中的这一行对此#
我收到格式为的回复#我需要将其转换为哈希值(针对活跃商家)。目前我正在遍历变量并执行此操作:response.instance_variables.eachdo|r|my_hash.merge!(r.to_s.delete("@").intern=>response.instance_eval(r.to_s.delete("@")))end这有效,它将生成{:first="charlie",:last=>"kelly"},但它似乎有点hacky和不稳定。有更好的方法吗?编辑:我刚刚意识到我可以使用instance_variable_get作为该等式的第二部分,但这仍然是主要问题。