Data Tip addition not working

2 ビュー (過去 30 日間)
Elena Casiraghi
Elena Casiraghi 2019 年 11 月 4 日
コメント済み: Elena Casiraghi 2019 年 11 月 4 日
Dear, I'm trying to change the data tip of my plot and I get an error I relly can't understand
The code takes data from file: FertilitySoloCountries.xlxs (attached). Its a file reporting the fertility rate for each country (one country per row) and for 16 year intervals (on the column). I want to plot these trends. And I do with the following code.
close all;
clc
figPosition = [0 0 1 1];
data = readtable('FertilitySoloCountries.xlsx', 'PreserveVariableNames', true);
yearRange = data.Properties.VariableNames;
yearRange = yearRange(:,2:end);
countries = table2cell(data(:,1));
numCountries = numel(countries);
dataMat = table2array(data(:, 2:end));
numRange = size(dataMat,2);
numCols = 4;
numRows = floor(numRange/4);
meanEveryNation = mean(dataMat);
figSparks = figure('Name', 'With SparkLines', 'units','normalized','outerposition',figPosition);
hold on; plot(meanEveryNation, 'k--', 'LineWidth', 2);
colormap
for nC = 1: numel(countries)
hold on; h = plot(dataMat'); %legend(countries);
addTip = dataTipTextRow('country',countries{nC});
h.DataTipTemplate.DataTipRows(end+1) = addTip;
end
ax = gca;
ax.XTickLabelRotation = 90;
set(ax,'XTick',1:numel(yearRange), 'XTickLabel', yearRange, 'fontsize', 6);
saveas(figSparks, 'PlotPerRange.jpg');
The code worked until I wanted to add a data tip. When I do that, matlab says:
Expected one output from a curly brace or dot indexing expression, but there were 209 results.
Error in PlotFertilitaPulito (line 23)
h.DataTipTemplate.DataTipRows(end+1) = addTip;
Where am I making it wrong?
I have been using datatips in another work... and it worked!

採用された回答

Jan Studnicka
Jan Studnicka 2019 年 11 月 4 日
close all;
clc
figPosition = [0 0 1 1];
data = readtable('FertilitySoloCountries.xlsx', 'PreserveVariableNames', true);
yearRange = data.Properties.VariableNames;
yearRange = yearRange(:,2:end);
countries = table2cell(data(:,1));
numCountries = numel(countries);
dataMat = table2array(data(:, 2:end));
numRange = size(dataMat,2);
numCols = 4;
numRows = floor(numRange/4);
meanEveryNation = mean(dataMat);
figSparks = figure('Name', 'With SparkLines', 'units','normalized','outerposition',figPosition);
hold on; plot(meanEveryNation, 'k--', 'LineWidth', 2);
colormap
h = plot(dataMat');
for nC = 1: numel(countries)
addTip = dataTipTextRow('country',repmat(string(countries{nC}),16,1));
h(nC).DataTipTemplate.DataTipRows(end+1) = addTip;
end
ax = gca;
ax.XTickLabelRotation = 90;
set(ax,'XTick',1:numel(yearRange), 'XTickLabel', yearRange, 'fontsize', 6);
saveas(figSparks, 'PlotPerRange.jpg');
  1 件のコメント
Elena Casiraghi
Elena Casiraghi 2019 年 11 月 4 日
Thanks!
You're true!!!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeAnnotations についてさらに検索

タグ

製品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by