[英]Why Matlab2tikz can't show figures with categorial data?
I plotted a bubble chart using scatter plot in Matlab with text lables on x axis and integer numbers on y axis.我使用 Matlab 中的散点 plot 绘制了气泡图,x 轴上带有文本标签,y 轴上带有 integer 数字。 The bubble sizes are also considered as integer numbers.气泡大小也被视为 integer 数字。 I included both code and figure of my chart.我包括了我的图表的代码和图形。 When I try to transform the figure to tikz using "matlab2tikz" library, I see the following error: "Error using categorical/cat (line 69): Can not concatenate a double array and a categorical array".当我尝试使用“matlab2tikz”库将图形转换为 tikz 时,我看到以下错误:“使用分类/cat 时出错(第 69 行):无法连接双精度数组和分类数组”。 I don't have any double numbers in my values.我的价值观中没有任何双数。 How can I transform this figure to tikz format?如何将此图转换为 tikz 格式?
x = ["C","A", "P", "K"]; %x lables
x1=categorical(x);
y = [33,68,200,14];% values
y1 = [48,177,200,16];
y2=[6,6,200,3];
sz = [35,7, 10, 56];%Bubble sizes
sz1=[25,7, 30, 53];
sz2=[44, 8,4,10];
scatter(x1,y,sz,'g','LineWidth',2);
hold on
scatter(x1,y1,sz1,'b','LineWidth',2);
hold on
scatter(x1,y2,sz2,'r','LineWidth',2);
hold off
legend({'y = Method1','y = Method2', 'y = Method3'},'Location','north');
title('NewModel');
ylabel('%Value');
saveas(gcf,'test.png');
You do have double numbers.你确实有双数。 y
, y1
and y2
are double whereas x1
is categorical which is why you are getting that error. y
, y1
和y2
是双倍的,而x1
是分类的,这就是您收到该错误的原因。
For your case, the error can be fixed by changing the square brackets to curly brackets in line 4052. ie change:对于您的情况,可以通过将第 4052 行中的方括号更改为大括号来修复错误。即更改:
data = [xData(:), yData(:)]; %line 4052 of matlab2tikz.m
to:至:
data = {xData(:), yData(:)};
The reason is what the error message says.原因是错误消息所说的。 You have categorical xData
and double yData
.你有分类xData
和双yData
。 These cannot be concatenated into a regular array.这些不能连接成常规数组。 A cell array is for combining different types of data.元胞数组用于组合不同类型的数据。
Similarly,相似地,
data=applyHgTransform(m2t,[xData(:), yData(:), zData(:)]); %line 4056 of matlab2tikz.m
should be modified to the following if you are plotting in 3D and have mixed data type:如果您在 3D 中绘图并且具有混合数据类型,则应修改为以下内容:
data=applyHgTransform(m2t,{xData(:), yData(:), zData(:)});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.