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

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.

Related

Google charts, is it possible to have 2 different vertical axis values?

For better understanding of this question, let me show a working example in TradingView webpage, on which the following chart shows the combination of Momentum (area chart) + ADX (line chart):
As you can see, there are 2 vertical values, at left side is the ADX which the scale goes usually from 0 to 60(+-), but the right side, it can grow much more.
On my attempt to achieve the same here, the momentum (area chart) has a huge range, and the adx (lineal chart) goes from 0 to 60, so when it tries to fit both values under the same scale, my blue line looks like it's almost zero, in comparison with the area chart values. (Mouse-over the blue line showing that is currently 43)
So I think you get the point, would it be possible to have 2 scales/vAxis for each series of values?
I checked documentation already but nothing here seems to refer to what I mention:
https://developers.google.com/chart/interactive/docs/gallery/combochart
And just in case you need the options provided to the chart, nothing advanced, just the basic examples:
options:{
seriesType: 'area',
series: {
0: { type: 'line', color: 'blue' }
}
};
use option --> targetAxisIndex -- in the series option...
zero is the default v-axis
targetAxisIndex: 0
to create a second v-axis, assign one of the series to index 1
series: {
1: {
targetAxisIndex: 1
}
}
Found the solution over this post in the documentation, it is conceptually known as DUAL-Y Charts
https://developers.google.com/chart/interactive/docs/gallery/columnchart#dual-y-charts

Making a support structure "manifold" in openscad

I am trying to build a support structure around a cylinder in openscad, but I cannot seem to make the angled part of the structure "manifold"
inner_slide_tube_inner_radius=14.9/2;
leadpipe_wall_thickness=14.9/2;
leadpipe_length=200;
mouthpiece_receiver_large_radius=0.546*25.4/2;
NoSpokes = 4;
SpokesWide = 3;
SpokesHigh = 3;
SpokesLong = leadpipe_length/2*0.75;
SpokesLong2 = leadpipe_length/2;
//if I comment out this section, then I can render a single support angle part when NoSpokes=1
for (i=[1:NoSpokes])
rotate([0,0,360/NoSpokes*i])
translate([mouthpiece_receiver_large_radius+leadpipe_wall_thickness,-SpokesWide/2,0])
cube([SpokesLong, SpokesWide, SpokesHigh]);
//
for (i=[1:NoSpokes])
rotate([0,0,360/NoSpokes*i])polyhedron(
points=[
[mouthpiece_receiver_large_radius+SpokesLong+leadpipe_wall_thickness-SpokesHigh, -SpokesWide/2, SpokesHigh],
[mouthpiece_receiver_large_radius+SpokesLong+leadpipe_wall_thickness-SpokesHigh, SpokesWide/2, SpokesHigh],
[inner_slide_tube_inner_radius, SpokesWide/2, SpokesLong2],
[inner_slide_tube_inner_radius, -SpokesWide/2, SpokesLong2],
[mouthpiece_receiver_large_radius+SpokesLong+leadpipe_wall_thickness, -SpokesWide/2, SpokesHigh],
[mouthpiece_receiver_large_radius+SpokesLong+leadpipe_wall_thickness, SpokesWide/2, SpokesHigh],
[inner_slide_tube_inner_radius, SpokesWide/2, SpokesLong2+SpokesHigh],
[inner_slide_tube_inner_radius, -SpokesWide/2, SpokesLong2+SpokesHigh]],
faces=[[1,0,3,2],
[1,5,4,0],
[2,3,7,6],
[1,5,6,2],
[0,4,7,3],
[4,5,6,7]
]);
I know that this is really naive question, but I am rather stuck as I keep getting the warning WARNING: Object may not be a valid 2-manifold and may need repair!
Any help would be greatly appreciated to get rid of the warning.
The reason your design is not manifold is that some of your polygon don't have the correct winding order. In OpenSCAD, if you preview your design using F2 (Thrown Together), such wrongly winded polygons will be highlighted in pink.

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)

different RA/Decs returned by pyEphem

I using pyEphem to calculate RA/Decs of satellites and I'm confused by the different
values computed and described on
http://rhodesmill.org/pyephem/radec.html
this bit of code
sat=ephem.readtle("SATNAME ", \
"1 38356U 12030A 14148.90924578 .00000000 00000-0 10000-3 0 5678",\
"2 38356 0.0481 47.9760 0002933 358.9451 332.7970 1.00270012 3866")
gatech = ephem.Observer()
gatech.lon, gatech.lat = '-155.47322222', '19.82561111'
gatech.elevation = 4194
gatech.date = '2014/01/02 07:05:52'
sat.compute(gatech)
print 'a_ra=',sat.a_ra,'a_dec=',sat.a_dec,'g_ra=',sat.g_ra,'g_dec=',sat.g_dec,'ra=',sat.ra,'dec=',sat.dec
gives
a_ra= 0:52:40.75 a_dec= -3:15:23.7 g_ra= 1:14:10.55 g_dec= 0:06:09.8 ra= 0:53:23.57 dec= -3:10:50.5
if I change JUST the observers location to say
gatech.lon, gatech.lat = '-5.47322222', '19.82561111'
I get
a_ra= 1:15:36.95 a_dec= -2:32:29.9 g_ra= 1:14:10.55 g_dec= 0:06:09.8 ra= 1:16:19.75 dec= -2:28:04.6
I thought the observers position only came into the calculation of sat.ra and sat.dec
so was suprised to see a_ra and a_dec had changed.
What am I missing?
Thanks
Ad
Per the last paragraph of the “body.compute(observer)” section of the Quick Reference:
http://rhodesmill.org/pyephem/quick.html#body-compute-observer
For earth satellite objects, the astrometric coordinates [meaning a_ra and a_dec] are topocentric instead of geocentric, since there is little point in figuring out where the satellite would appear on a J2000 (or whatever epoch you are using) star chart for an observer sitting at the center of the earth.
And in the issue that has been opened about this behavior, the project is open to suggestions about where this text can appear more prominently to prevent future confusion for users:
https://github.com/brandon-rhodes/pyephem/issues/55