How to draw a nice bar with grid lines in background? - matlab

I need help to plot the results in 2 bar graphs (with different colours). The resulting figure needs to have grid lines.
How to output a nice plot?
The data is as follows:
x-axis is speed from 2 to 50 and the increment is 2.
A = [2.2214523, 1.81357174, 1.61390754, 1.47970432, 1.29658232, 1.26972206, 1.16870602, 1.17688473, 1.30224695, 1.23878984, 1.18680971, 1.26357444, 1.14138904, 0.95115584, 1.16134491, 1.021687, 0.98920929, 1.04342079, 0.99826255, 0.8655728, 0.91652594, 0.85538917, 0.78884521, 0.91927867, 0.86419587]
B = [187.579709, 25.312399, 11.3572375, 9.3078819, 8.37157321, 7.66729673, 7.36497776, 6.96170053, 6.69527653, 6.77668306, 6.19491326, 6.01744432, 5.61383228, 5.59616954, 5.26652168, 5.26946343, 5.19543014, 5.11049461, 5.05088231, 4.917285, 4.9581181, 4.78929521, 4.772158, 4.7373291, 4.81629734]

Related

Label file of yolov7

I downloaded the object model yolov7 (https://github.com/WongKinYiu/yolov7) and the coco dataset. Then there are the folders coco\images and coco\labels.
I opened the image "coco\images\train2017\000000000034.jpg" and the corresponding label file "coco\labels\train2017\000000000034.jpg".
An annotation for the yolo-model has to be in the form:
<object_class> <x_center> <y_center>
The content of the label file is:
22 0.00746875 0.0539294 0.117891 0.0921412
0.231297 0.110118 0.2895 0.0674118
0.331281 0.0472 0.3865 0.0696706
0.423813 0.0943765 0.446188 0.105624
0.467078 0.1528 0.517813 0.182024
0.577516 0.253929 0.658094 0.379765
0.690922 0.532588 0.687937 0.6
0.650625 0.555059 0.658094 0.644941
0.668547 0.755059 0.676 0.838212
0.658094 0.894376 0.613328 0.925835
0.589453 0.914612 0.590938 0.856188
0.552141 0.791012 0.523781 0.725835
0.528266 0.633718 0.498422 0.577529
0.444703 0.505624 0.407391 0.505624
0.395453 0.541576 0.417844 0.591012
0.450672 0.642706 0.456641 0.642706
0.461109 0.725835 0.458125 0.786518
0.450672 0.853929 0.444703 0.898871
0.401422 0.869671 0.411875 0.815741
0.423813 0.734824 0.425297 0.694376
0.361125 0.608988 0.316359 0.588753
0.280547 0.703365 0.271594 0.757294
0.261141 0.829224 0.268609 0.869671
0.277562 0.901129 0.250703 0.937082
0.222344 0.939318 0.231297 0.901129
0.222344 0.844941 0.238766 0.7236
0.246219 0.642706 0.271594 0.510118
0.182062 0.507859 0.0999844 0.525835
0.0208906 0.494376 0.0015 0.0516941
For what all numbers stand for?
I think you downloaded the segmentation dataset.
Go in the cloned yolov7 directory and run
bash scripts/get_coco.sh
to get the object detection dataset
The number looks like normalized values for the segmentation of the image. The first number corresponds to the class label, and the point makes a mask for the object detected
Segmentation draw a mask around the object. So the numbers above represent the coordinates for the mask. Similar to bounding box but bounding box have 4 values (x, y, width, height), a segmentation have a mask. The number of points in a mask are not always same in number so you will see different number of points for different object or even for same object. Masks in the image above you can see that there are bounding boxes with masks. so each value represent a point of the mask

SSRS: Custom colors for the Category axis of a stacked bar chart

I have a stacked bar chart that only ever has 5 categories(but the value of the categories change from year to year, it is a sliding 5 year window).
I have successful customised the bars to the colors I want.
But now I wish to make the label of each Category the same color as the customised bar color.
Is there a way to do this?
You can use custom code for this.
In Report Properties | Code, you can paste in the following code:
Private colourPalette As String() = {"#418CF0", "#FCB441", "#DF3A02", "#056492", "#BFBFBF", "#1A3B69", "#FFE382", "#129CDD", "#CA6B4B", "#005CDB", "#F3D288", "#506381", "#F1B9A8", "#E0830A", "#7893BE"}
Private count As Integer = 0
Private mapping As New System.Collections.Hashtable()
Public Function GetColour(ByVal groupingValue As String) As String
If mapping.ContainsKey(groupingValue) Then
Return mapping(groupingValue)
End If
Dim c As String = colourPalette(count Mod colourPalette.Length)
count = count + 1
mapping.Add(groupingValue, c)
Return c
End Function
This will give you the option of the pastel colour palette. If you want other colours, simply replace the hex colour codes with values of your choice.
To use this, simply use the following expression:
=Code.GetColour(Fields!Thingy.Value)
Use this on your series and your label fill expressions. This will ensure that the same colour appears for both. If you have multiple graphs with the same values in, this will also ensure that the same data series across multiple graphs always have the same colour.

Gantt Chart in Matlab

Do you know how to plot a Gantt chart in Matlab without using a third-party software?
At the end I would love to obtain something like this:
What I was able to obtain so far is
using this code:
% Create data for childhood disease cases
measles = [38556 24472 14556 18060 19549 8122 28541 7880 3283 4135 7953 1884]';
mumps = [20178 23536 34561 37395 36072 32237 18597 9408 6005 6268 8963 13882]';
chickenPox = [37140 32169 37533 39103 33244 23269 16737 5411 3435 6052 12825 23332]';
% Create a stacked bar chart using the bar function
fig = figure;
bar(1:12, [measles mumps chickenPox], 0.5, 'stack');
axis([0 13 0 100000]);
title('Childhood diseases by month');
xlabel('Month');
ylabel('Cases (in thousands)');
legend('Measles', 'Mumps', 'Chicken pox');
That is not what I want but, maybe, goes in this direction
Here, I share the solution I have just found (maybe it is not the most elegant one but it works for the purpose I have):
[the main idea is to draw a bar and "delete" the beginning overdrawing up on it another white bar]
Let's say you have two vector:
start =[6907402; 2282194; 4579536; 2300332; 10540; 2307970; 4603492; 0];
stop =[9178344; 9168694;6895050; 4571400; 2280886; 4579044; 6897152 ;2271186];
There are 8 elements in each: every element is a task. In the start array, there is the start time of each task and in stop there is the end of the "execution" of a given task.
barh(stop)
hold on
barh(start,'w')
At the end here you have the Gantt:
UPDATE:
My scripts are evolved of course and, more, on the matlab website, there is more information. Here 2 example more to complete the answer:
Option 1:
Positions=[1,2,3,4];
Gap_Duration=[0,2,5,3,5,3;
3,5,3,5,3,4;
9,3,0,0,12,2;
13,2,2,2,8,3];
barh(Positions,Gap_Duration,'stacked');
Option 2:
Positions=[1,2,3,4];
Gap_Duration=[0,2,5,3,5,3;
3,5,3,5,3,4;
9,3,0,0,12,2;
13,2,2,2,8,3];
barh(Positions,Gap_Duration,'stacked');
set(H([1 3 5]),'Visible','off')

bar chart display all cateogries

I have a bar chart. It has 25 bars all representing a different category. The chart is fine however it only prints out a few of the categories.
I thought by using the line below that it would display all 25 categories that I have specified in x_labels.
set(gca,'XtickL',x_labels);
I also use the method rotateXLabel and rotate the labels 90 degrees so they are not over writing each other. However still only display some of the categories. How can I display all of them?
update
Here is my data,
'Health Care' 4.72629799981083
'Capital Goods' 4.09458147368759
'Transp' 3.98149295925542
'Media' 1.79439005788530
'Insurance' 1.69956150439052
'Commer Serv' 1.39773924375053
'Food & Staples' 1.37870312358688
'Tech Hardw' 1.14006008338028
'Div Finan' 1.07437424540054
'Retailing' 0.799227696500581
'Cons Durab' 0.484704646767555
'Semiconduct' -0.0668927175281457
'Cons Serv' -0.0994263844790881
'Software' -1.13770277184728
'Auto&Comp' -1.14193637823934
'Materials' -1.52052729345776
'Real Estate' -1.58166267932780
'HH & Prod' -1.68076878183555
'Food Bever' -1.73283367572542
'Pharma' -1.90119783888618
'Telecom' -2.04480219189470
'Utilities' -2.20510498991084
'Energy' -2.36405808621777
'Banks' -5.09421924506606
another update
Found the solution here. Its not quite 100% perfect though as some of my labels are too long so the chart cuts them off. Need to work out how to get round that issue
[pp,h1,h2]=plotyy((1:length(risk_tot)),risk_tot,(1:length(risk_tot)),risk_cont,'bar','stem');
xData = get(h1,'XData');
set(gca,'Xtick',linspace(xData(1),xData(end),length(x_labels(:, 1))));
Is this what you are looking for?:
value is vector with the provided values
label is a cell with the provided strings
bar(value);
set(gca, 'XTick', 1:length(value))
set(gca, 'XTickLabel', label)
grid on
rotateXLabels(gca(), 90)

Is there a limit to the amount of data you can put in a MATLAB pie/pie3 chart?

I have everything going swimmingly on my pie chart and 3D pie charts within MATLAB for a dataset, however, I noticed that even though I have 21 pieces of data for this pie-chart being fed into the pie-chart call, only 17 appear.
PieChartNums = [ Facebook_count, Google_count, YouTube_count, ThePirateBay_count, StackOverflow_count, SourceForge_count, PythonOrg_count, Reddit_count, KUmail_count, Imgur_count, WOWhead_count, BattleNet_count, Gmail_count, Wired_count, Amazon_count, Twitter_count, IMDB_count, SoundCloud_count, LinkedIn_count, APOD_count, PhysOrg_count];
labels = {'Facebook','Google','YouTube','ThePirateBay','StackOverflow', 'SourceForge', 'Python.org', 'Reddit', 'KU-Email', 'Imgur', 'WOWhead', 'BattleNet', 'Gmail', 'Wired', 'Amazon', 'Twitter', 'IMDB', 'SoundCloud', 'LinkedIn', 'APOD', 'PhysOrg'};
pie3(PieChartNums)
legend(labels,'Location','eastoutside','Orientation','vertical')
This goes for the labels and the physical graph itself.
Excuse the poor formatting in terms of the percentage cluster, this is just a rough version. I tried every orientation and even splitting labels between the orientations without any luck.
Quasi-better resolution for Pie Chart -- Imgur Link
Like Daniel said - it appears that there simply isn't any non-negative data for the missing slices. I tried reproducing your problem with the following initialization, yet it resulted in normal-looking chart:
[ Facebook_count, Google_count, YouTube_count, ThePirateBay_count, ...
StackOverflow_count, SourceForge_count, PythonOrg_count, Reddit_count, ...
KUmail_count, Imgur_count, WOWhead_count, BattleNet_count, Gmail_count, ...
Wired_count, Amazon_count, Twitter_count, IMDB_count, SoundCloud_count, ...
LinkedIn_count, APOD_count, PhysOrg_count] = deal(0.04);
In order to verify this hypothesis - could you provide the data you're using for the chart? Do you get any warnings when plotting the chart?
From inside the code of pie.m:
if any(nonpositive)
warning(message('MATLAB:pie:NonPositiveData'));
x(nonpositive) = [];
end
and:
for i=1:length(x)
if x(i)<.01,
txtlabels{i} = '< 1%';
else
txtlabels{i} = sprintf('%d%%',round(x(i)*100));
end
end
You can see that MATLAB doesn't delete valid slices, but only renames them if the data values are small.