How do I changethe label in a compass graph

14 views (last 30 days)
olivier task
olivier task on 16 Jan 2021
Commented: dpb on 17 Jan 2021
Hello
Here is my code , I find it in the documentation.
but I always get a mathlab error and I don't understand why.
Thank's , Olivier
% Channel ID to read data from
readChannelID = 926212;
WindDirFieldID = 4;
WindSpeedFieldID = 3;
readAPIKey = 'XXXXXXXXXXXXXXX';
windDir = thingSpeakRead(readChannelID,'Fields',WindDirFieldID,'NumPoints',10,...
'ReadKey',readAPIKey);
windSpeed = thingSpeakRead(readChannelID,'Fields',WindSpeedFieldID,'NumPoints',10,...
'ReadKey',readAPIKey);
rad = windDir*2*pi/360;
rad = (rad+pi/2);
u = -cos(rad) .* windSpeed;
v = sin(rad) .* windSpeed;
title('anemo');
%pax = gca;
angles = 0:45:360;
pax.ThetaTick = angles;
labels = {'E','NE','N','NW','W','SW','S','SE'};
pax.ThetaTickLabel = labels;
compass(u,v);

Answers (1)

dpb
dpb on 16 Jan 2021
Edited: dpb on 16 Jan 2021
Well, the above code commented out
pax=gca;
so the handle to the axes is either undefined or refers to a probably no longer existing object if the variable exists from a previous run. Or, if there is no variable pax the first time the code is run it will be created by the dot notation as a struct:
windSpeed=randi(30,size(windDir));
windDir=deg2rad(randi(360,10,1)-1);
u = -cos(rad) .* windSpeed;
v = sin(rad) .* windSpeed;
title('anemo');
%pax = gca;
angles = 0:45:360;
pax.ThetaTick = angles;
labels = {'E','NE','N','NW','W','SW','S','SE'};
pax.ThetaTickLabel = labels;
compass(u,v);
executed when there was no variable pax in the workspace resulted in
>> pax
pax =
struct with fields:
ThetaTick: [0 45 90 135 180 225 270 315 360]
ThetaTickLabel: {'E' 'NE' 'N' 'NW' 'W' 'SW' 'S' 'SE'}
>>
But, the bigger problem is that the example is for polarplot which creates a PolarAxes object and you drew a compass plot which uses a regular Cartesian axes object which does not have the properties 'ThetaTick', 'ThetaTickLabel' but computes and draws a polar coordinate system axis/lines in cartesian coordinates.
A quick perusal didn't uncover just how those are done or where those properties might be buried but they're not easily accessible it seems.
Alternatively, you might try to draw a polarplot() object to label and then add the compass plot on top...but I'm not sure how you'd turn off the labels...and I don't have time to delve more deeply at the moment, sorry.
This looks like a Q? to official support, mayhaps with a request for enhancement to get compass() to also use the polar axes object.
  4 Comments
olivier task
olivier task on 17 Jan 2021
Thank you for your investment. I am finally using polarplot. I can't draw the arrow, but the plot is enough.
https://thingspeak.com/apps/matlab_visualizations/319108?size=iframe
Best regards. Olivier
dpb
dpb on 17 Jan 2021
Don't blame you... :)
You could probably add annotations for the arrowheads to polarplot although I've not explored that option.

Sign in to comment.

Communities

More Answers in the  ThingSpeak Community

Categories

Find more on Polar Plots in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!