How to delete the 'SourceTable' property of a set of data when using GeoBubble?
4 ビュー (過去 30 日間)
古いコメントを表示
I am trying to plot a set of earthquakes from an excel spreadsheet. I am using their magnitudes to create corresponding bubble sizes and colors based on how extreme the earthquake was. The size of bubble works well, but when I include the 'ColorData' piece, I am given the error message, "Setting the 'ColorData' property after setting the 'SourceTable' property is not supported." I am not sure how I set the 'SourceTable' property or if there is a way to get rid of it. Or if there is a way to use ColorData with the 'SourceTable' property, that would be appreciated as well. As soon as the " 'ColorData','Magnitude' " section is taken out, the code runs well. I have tried the command "clear all", in case I had accidentally set the 'SourceTable' property to something in a previous run, but that didn't change the error message at all. Here is the code:
p = readtable('RealQuakes.xlsx');
figure gb = geobubble(p,6,7,'SizeVariable','Magnitude','ColorData','Magnitude','Basemap','colorterrain');
0 件のコメント
採用された回答
Amy Haskins
2018 年 6 月 12 日
You will need to use either all 'Variable' properties or all 'Data' properties with geobubble. The properties whose names end in 'Variable' are for specifying a column from the source table. The ones that end in 'Data' should be used when you have vector data. In this case, replacing 'ColorData' with 'ColorVariable' will fix the error you saw, but you will get another error because the function also expects the 'ColorVariable' to be categorical. For this, you could add a new column to the table using the discritize function to bin the magnitudes into categories. It would look something like this:
p.MagnitudeCat = discretize(p.Magnitude,0:2:10,'categorical');
gb = geobubble(p,6,7,'SizeVariable','Magnitude','ColorVariable','MagnitudeCat')
The 'SourceTable' property stores the table you specified as the first input argument (p). You could in theory set the 'SourceTable' to a different table with the same column names thereby updating your chart. For example, if you had data for 2017 and 2018 in separate tables you could do the following:
p2017 = readtable('RealQuakes2017.xlsx');
p2017.MagnitudeCat = discretize(p2017.Magnitude,0:2:10,'categorical');
gb = geobubble(p2017,6,7,'SizeVariable','Magnitude','ColorVariable','MagnitudeCat')
p2018 = readtable('RealQuakes2018.xlsx');
p2018.MagnitudeCat = discretize(p2018.Magnitude,0:2:10,'categorical');
gb.SourceTable = p2018; % Swap out the 2017 data with 2018 data
To instead use the 'Data' properties would look like the following. Note, in this workflow you are supplying vectors of data pulled from the table and not the table itself. There is no need to add a new column to the table with this workflow, instead you can supply the data directly. The 'SourceTable' property will be empty in this case.
gb = geobubble(p.Latitude,p.Longitude, ...
'SizeVariable',p.Magnitude, ...
'ColorVariable',discretize(p.Magnitude,0:2:10,'categorical'))
4 件のコメント
Amy Haskins
2018 年 6 月 25 日
My guess is that the data in your year column is for some reason in a char format instead of a numeric one. You would either need to convert it to a numeric format using something like str2double, or use strcmp instead of ==.
tsunamisEQ = tsunamis(strcmp(tsunamis.Cause, 'Earthquake'),:)
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Geographic Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!