- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
极坐标直方图对于绘制具有多个条目的堆叠条形图非常有用。图形目标的下图中提供了一个示例。这可以在 R 中使用 ggplot2 以某种方式轻松完成。在 matlab 中与 'rose' 类似的功能似乎不允许这样的结果。
作为起点,这里是我所拥有的:
% inputs
l = [1 1.4 2 5 1 5 10;
10 5 1 5 2 1.4 1;
5 6 3 1 3 2 4];
alpha = [10 20 50 30 25 60 50]; % in degrees
label = 1:length(alpha);
% setings
offset = 1;
alpha_gap = 2;
polarHist(l,alpha,label)
函数 polarHist
function polarHist(data,alpha,theta_label,offset,alpha_gap,ticks)
if nargin 360-alpha_gap*length(alpha)
error('Covers more than 360°')
end
% code
theta_right = 90 - alpha_gap + cumsum(-alpha) - alpha_gap*[0:length(alpha)-1];
theta_left = theta_right + alpha;
col = get(gca,'colororder');
for j = 1:size(data,1)
hold all
if j == 1
rho_in = kron(offset*ones(1,length(alpha)),[1 1]);
else
rho_in = rho_ext;
end
rho_ext = rho_in + kron(data(j,:),[1 1]);
for k = 1:size(data,2)
h = makewedge(rho_in(k),rho_ext(k),theta_left(k),theta_right(k),col(j,:));
if j == size(data,1) && ~isempty(theta_label)
theta = theta_right(k) + (theta_left(k) - theta_right(k))/2;
rho = rho_ext(k)+1;
[x,y] = pol2cart(theta/180*pi,rho);
lab = text(x,y,num2str(theta_label(k),'%0.f'),'HorizontalAlignment','center','VerticalAlignment','bottom');
set(lab, 'rotation', theta-90)
end
end
end
axis equal
theta = linspace(pi/2,min(theta_right)/180*pi);
%ticks = [0 5 10 15 20];
rho_ticks = offset + ticks;
ax = polar([ones(length(ticks(2:end)),1)*theta]',[rho_ticks(2:end)'*ones(1,length(theta))]');
set(ax,'color','w','linewidth',1.5)
axis off
for i=1:length(ticks)
[x,y] = pol2cart((90)/180*pi,rho_ticks(i));
text(x,y,num2str(ticks(i)),'HorizontalAlignment','right');
end
makewedge
function hOut = makewedge(rho1, rho2, theta1, theta2, color)
%MAKEWEDGE Plot a wedge.
% MAKEWEDGE(rho1, rho2, theta1, theta2, color) plots a polar
% wedge bounded by the given inputs. The angles are in degrees.
%
% h = MAKEWEDGE(...) returns the patch handle.
ang = linspace(theta1/180*pi, theta2/180*pi);
[arc1.x, arc1.y] = pol2cart(ang, rho1);
[arc2.x, arc2.y] = pol2cart(ang, rho2);
x = [arc1.x arc2.x(end:-1:1)];
y = [arc1.y arc2.y(end:-1:1)];
newplot;
h = patch(x, y, color);
if ~ishold
axis equal tight;
end
if nargout > 0
hOut = h;
end
结果与 ggplot2
的输出还相去甚远,但我认为这是一个开始。我正在努力添加图例(l
行)...
最佳答案
您可以通过使用 hist
获取每个元素的累积 bin 来简化您的问题,然后将其归一化为百分比并使用补丁将其绘制为极坐标堆积条。
例如,假设您的数据包含 30 个元素,每个元素有 1000 个样本,每个样本可以是 1,2 或 3。
data=randi(3,1000,30); %create random data
[data_bins,~]=hist(data',3); %Get the accumulated bins
data_bins=data_bins/1000; %Normalize values to percentages
您可以绘制正常的堆叠条形图以可视化数据
function stackedbar(ymatrix1)
% Create figure
figure1 = figure('Color',[1 1 1]);
% Create axes
axes1 = axes('Parent',figure1,...
'YTickLabel',{'0','10%','20%','40%','80%','100%'},...
'YTick',[0 10 20 40 80 100],...
'XTick',[1:length(ymatrix1)],...
'FontWeight','bold',...
'FontSize',16);
xlim(axes1,[0 length(ymatrix1)+1]);
ylim(axes1,[0 100]);
hold(axes1,'all');
% Create multiple lines using matrix input to bar
bar1 = bar(ymatrix1,'EdgeColor',[1 1 1],'BarLayout','stacked',...
'Parent',axes1);
set(bar1(1),...
'FaceColor',[0.137254908680916 0.372549027204514 0.647058844566345],...
'EdgeColor',[0.137254908680916 0.372549027204514 0.647058844566345],...
'DisplayName','uno');
set(bar1(2),...
'FaceColor',[0.223529413342476 0.619607865810394 0.168627455830574],...
'EdgeColor',[0.223529413342476 0.619607865810394 0.168627455830574],...
'DisplayName','dos');
set(bar1(3),'FaceColor',[0.850980401039124 0 0.0431372560560703],...
'EdgeColor',[0.850980401039124 0 0.0431372560560703],...
'DisplayName','tres');
% Create legend
legend1 = legend(axes1,'show');
set(legend1,...
'Position',[0.902123631386861 0.416961133287318 0.0826277372262772 0.16808336774016]);
plot([0,length(ymatrix1)],[10,10],'w')
plot([0,length(ymatrix1)],[20,20],'w')
plot([0,length(ymatrix1)],[40,40],'w')
plot([0,length(ymatrix1)],[80,80],'w')
您可以使用 pol2cart
使用与极坐标相同的值,并通过在一个补丁中绘制所有相同的颜色条,您可以在这些补丁上调用 legend
function polarstackedbar(data,offset)
% Data is the normalized values and offset is the size of the white circle at the center
yticks=[10,20,40,80,100];
% Create figure
figure1 = figure('Color',[1 1 1]);
% Create axes
axes1 = axes('Parent',figure1,'ZColor',[1 1 1],'YColor',[1 1 1],...
'XColor',[1 1 1],...
'PlotBoxAspectRatio',[434 342.3 2.282],...
'FontWeight','bold',...
'FontSize',16,...
'DataAspectRatio',[1 1 1]);
temp=[data(:,1)+data(:,2)+data(:,3)+offset,data(:,1)+data(:,2)+data(:,3)+offset,zeros(length(data),1)]';
temp=temp(:);
temp=[0;temp];
temp2=[data(:,1)+data(:,2)+offset,data(:,1)+data(:,2)+offset,zeros(length(data),1)]';
temp2=temp2(:);
temp2=[0;temp2];
temp3=[data(:,1)+offset,data(:,1)+offset,zeros(length(data),1)]';
temp3=temp3(:);
temp3=[0;temp3];
th=(1:length(data))*3*pi/(2*length(data));
themp=[th;th;th];
themp=themp(:);
themp=[0;0;themp];
themp(end)=[];
% Create patch
[XData1,YData1]=pol2cart(themp,temp);
p1=patch('Parent',axes1,'YData',YData1,...
'XData',XData1,...
'FaceColor',[0.850980401039124 0 0.0431372560560703],...
'EdgeColor',[0.850980401039124 0 0.0431372560560703],...
'DisplayName','tres');
% Create patch
[XData2,YData2]=pol2cart(themp,temp2);
p2=patch('Parent',axes1,'YData',YData2,...
'XData',XData2,...
'FaceColor',[0.223529413342476 0.619607865810394 0.168627455830574],...
'EdgeColor',[0.223529413342476 0.619607865810394 0.168627455830574],...
'DisplayName','dos');
% Create patch
[XData3,YData3]=pol2cart(themp,temp3);
p3=patch('Parent',axes1,'YData',YData3,...
'XData',XData3,...
'FaceColor',[0.137254908680916 0.372549027204514 0.647058844566345],...
'EdgeColor',[0.137254908680916 0.372549027204514 0.647058844566345],...
'DisplayName','uno');
% Create patch
[XData4,YData4]=pol2cart(themp,offset*ones(3*length(data)+1,1));
patch('Parent',axes1,'YData',YData4,...
'XData',XData4,...
'LineStyle','none',...
'FaceColor',[1 1 1]);
% Create legend
legend([p3,p2,p1]);
hold
% Create labels
for i=1:length(data)
[x,y]=pol2cart((i-0.5)*3*pi/(2*length(data)),offset+5+100);
h=text(x,y,num2str(i),'HorizontalAlignment','center');
set(h,'rotation',rad2deg((i-0.5)*3*pi/(2*length(data)))-90+90*sign(cos((i-0.5)*3*pi/(2*length(data)))));
[x,y]=pol2cart((i)*3*pi/(2*length(data)),offset+15+100);
plot([0,x],[0,y],'w');
end
thetas=0:0.01:2*pi;
for tick=yticks
[X,Y]=pol2cart(thetas,tick+offset*ones(1,629));
plot(X,Y,'w')
text(X(472)+15,Y(472),strcat(int2str(tick),'%'),'FontWeight','bold','FontSize',16,'HorizontalAlignment','center');
end
关于matlab - 创建极坐标直方图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38054152/
我有一个点(粉色圆圈),它有一个已知的 X 坐标和一个已知的 Y 坐标,但 Y 坐标> 坐标不正确。它当前位于目标贝塞尔曲线(部分位于白色正方形中的曲线)所在的点(如果它是两点之间的一条线)。我需要为
有一个基于QML 和QWT 的代码,一种具有更多可能性的图形生成器。技术要求之一是根据某个 X 坐标获得绘图曲线的 Y 坐标。 有一种不准确的方法 - 获取 QwtPlotCurve 的 QPoint
我目前正在将对象的 3D 坐标转换为 2D 坐标,然后在其上绘制 2D 文本(目前是对象名称): public static int[] getScreenCoords(double x, doubl
首先,我创建一个元组列表(要绘制的点)。每个元组由 3 个数字组成(x - 坐标,y - 坐标,c - 点的颜色) import random import matplotlib.pyplot as
我正在制作一个 2 人 Java 游戏,但我需要确保坐标保留在板上。 addPiece(1, 1, "X"); addPiece(8, 8, "O"); showBoard(); Scanner my
我想检查我是否正确使用了 scipy 的 KD 树,因为它看起来比简单的暴力破解要慢。 关于这个我有三个问题: Q1. 如果我创建以下测试数据: nplen = 1000000 # WGS84 lat
我有一个 GeoJSON 文件,我正在尝试处理它以便在谷歌地图上绘制一些功能。然而,问题在于坐标不是传统的纬度/经度表示法,而是一些大的六位/七位数字。示例: { "type":
我在使用坐标时遇到格式化问题。 public class Coordinate { public int x; public int y; public Coordinate( int x
我正在尝试获取当前位置的经度和纬度坐标。这是到目前为止我的代码: public class MainActivity extends AppCompatActivity { @Override pro
基本上,我需要获取从 OpenGL 中的贝塞尔曲线实现绘制的所有坐标。具体来说,我需要坐标来沿着弯曲的轨迹路径移动场景中的球体对象(棒球)。这是我用来绘制曲线的: GL2 gl = drawable.
现在我用 JAVA 遇到了一些问题,但不记得如何获取坐标系之间的长度。 例如。A 点 (3,7)B点(7,59) 我想知道如何计算a点和b点之间的距离。非常感谢您的回答。 :-) 最佳答案 A = (
我正在用 Pi2Go 机器人制作一个小项目,它将从超声波传感器获取数据,然后如果它看到一个物体,则放置一个 X,并放置 O 它当前所在的位置,我有两个问题:如何在 tkinter 上设置坐标位置?例如
如何在 pygame 中存储对象的先前坐标?我的问题可能有点难以解释,但我会尽力,如果您自己尝试我的代码以理解我的意思可能会有所帮助。 这就是我的游戏的内容。我希望这能让我的问题更容易理解。 我正在创
如何存储用户的当前位置并在 map 上显示该位置? 我能够在 map 上显示预定义的坐标,只是不知道如何从设备接收信息。 此外,我知道我必须将一些项目添加到 Plist 中。我怎样才能做到这一点? 最
我在 android 应用程序开发方面不是很熟练,我正在开发一个测试应用程序。我检测到了脸和眼睛,现在我要根据眼睛的坐标在脸上画一些像粉刺或疤痕的东西(例如脸颊上的眼睛下方)。稍后,我会把眼镜或帽子放
所以我正在使用 API 来检测图像中的人脸,到目前为止它对我来说效果很好。然而,我一直无法弄清楚如何将图像裁剪到脸上。我知道如何裁剪位图,但它需要获取位图中脸部的左上角位置以及宽度和高度。当我使用 查
我有 2 个表。第一个表包含以下列:Start_latitude、start_longitude、end_latitude、end_longitude、sum。 sum 列为空,需要根据第二张表进行填
有没有办法给 Google Maps API 或类似的 API 一个城镇名称,并让它返回城镇内的随机地址?我希望能够将数据作为 JSON 获取,以便我可以在 XCode 中使用 SwiftyJSON
我将坐标保存在 numpy 数组 x 和 y 中。现在我想要的只是获得一个多边形(分别是点数组),它用给定的宽度参数定义周围区域。 我遇到的问题是我需要一个没有(!)交叉点的多边形。但是,当曲线很窄时
我正在开发井字游戏 (3x3),所以我有 9 个按钮,我想做的是获取用户按下的按钮的坐标,并在按钮的位置插入图像。 例子: @IBOutlet weak var button1Outlet: UIBu
我是一名优秀的程序员,十分优秀!