So I am trying to make a plot with the x-axis reading as the dates in my data.frames.
However it keeps reading as 0,1,2,3,4,5,....,,20, instead of April-01,April-02...April-29
data.setup<-function(data,loc='yahoo',start.date=Sys.Date()-months(1),
end.date=Sys.Date()) {
getSymbols(data,src=loc)
x<-as.data.frame(window(get(data),
start=as.character(start.date),
end=as.character(end.date)))
x$dates<-row.names(x)
colnames(x)<-c('Open','High','Low','Close','Volume','Adjusted','Dates')
x<-x[c(7,1,2,3,4,5,6)]
return(return(x))
}
data<-data.setup('AAPL',start.date=Sys.Date()-months(1))
h1<-Highcharts$new()
h1$chart(type='line')
h1$xAxis(category=data$Dates,id='dates')
h1$series(data=data$Low,name='Low',xAxis='dates')
not category but categories.
# data
df <- data.frame(x = 1:10, y = rnorm(10), s = rnorm(10), z = letters[1:10])
# create plot object
p <- hPlot(y ~ x, data = df, size = "s", type = "line")
# set axis
p$xAxis(categories = as.character(seq(Sys.Date(), by = 1, length.out = 10)))
# show
p
Related
I have to plot some Venn diagrams to show intersections between arrays of strings. Let me explain: I have a category of names that includes three others that do not intersect each other. I want to understand which of these three occupies the largest percentage of the macro-category mentioned above. I would like to do it with MATLAB but I see that this development environment is somewhat devoid of such functions. If you have any ideas in mind I would be grateful.
Thanks in advance!
Venn Diagrams by Plotting Circles
Not the most elegant way but one method of plotting a Venn diagram can be plotting circles and filling the individual circles using a text() annotation/label. Unfortunately, here I manually placed where the labels are centred. Automating the label positioning may take several additional steps which I will leave out for simplicity. To find the intersections of the respective datasets I simply used the intersect() function.
A = {'A','B','C','D','E','F','G','H','I','L'};
B = {'A','B','C','D'};
C = {'E','F','G','H','I','L'};
%Finding the intersections of the arrays%
Intersection_AB = intersect(A,B);
fprintf("Intersection AB: ")
disp(Intersection_AB);
fprintf("\n");
Intersection_BC = intersect(B,C);
fprintf("Intersection BC: ")
disp(Intersection_BC);
fprintf("\n");
Intersection_AC = intersect(A,C);
fprintf("Intersection AC: ")
disp(Intersection_AC);
fprintf("\n");
Intersection_ABC = intersect(Intersection_AB,C);
fprintf("Intersection ABC: ")
disp(Intersection_ABC);
fprintf("\n");
clc;
clf;
Plotting_Interval = 0.01;
Angles_In_Radians = (0: Plotting_Interval: 2*pi);
Circle_Plot = #(X_Offset,Y_Offset,Radius) plot(X_Offset + Radius*cos(Angles_In_Radians),Y_Offset + Radius*sin(Angles_In_Radians));
hold on
%Plotting the 3 circles%
X_Offset_A = 0; Y_Offset_A = 2; Radius_A = 3;
Circle_A = Circle_Plot(X_Offset_A,Y_Offset_A,Radius_A);
fill(Circle_A.XData, Circle_A.YData,'r','FaceAlpha',0.2,'LineWidth',1);
X_Offset_B = -2; Y_Offset_B = -2; Radius_B = 3;
Circle_B = Circle_Plot(X_Offset_B,Y_Offset_B,Radius_B);
fill(Circle_B.XData, Circle_B.YData,'g','FaceAlpha',0.2,'LineWidth',1);
X_Offset_C = 2; Y_Offset_C = -2; Radius_C = 3;
Circle_Plot(X_Offset_C,Y_Offset_C,Radius_C);
Circle_C = Circle_Plot(X_Offset_C,Y_Offset_C,Radius_C);
fill(Circle_C.XData, Circle_C.YData,'b','FaceAlpha',0.2,'LineWidth',1);
title("Venn Diagram");
%Writing all the labels%
A_Label = strjoin(string(A));
text(X_Offset_A,Y_Offset_A,A_Label,'color','r');
B_Label = strjoin(string(B));
text(X_Offset_B,Y_Offset_B,B_Label,'color','g');
C_Label = strjoin(string(C));
text(X_Offset_C,Y_Offset_C,C_Label,'color','b');
AB_Label = strjoin(string(Intersection_AB));
text(-1.2,0,AB_Label);
BC_Label = strjoin(string(Intersection_BC));
text(0,-2,BC_Label);
AC_Label = strjoin(string(Intersection_AC));
text(1.2,0,AC_Label);
ABC_Label = strjoin(string(Intersection_ABC));
text(0,0,ABC_Label);
%Setting the labels to be relative to the centres%
set(findall(gcf,'type','text'),'HorizontalAlignment','center');
axis equal
axis off
Ran using MATLAB R2019b
Based on this question: Table fields in format in PDF report generator - Matlab, I converted the p table to be a DOM MATLAB Table. How can I color the header row, remove the underlining of its entries and apply the tableStyle on the rest of it.
With my code, I get all the table with the LightBlue color and the tableStyle is not applied.
Code:
function ButtonPushed(app, event)
import mlreportgen.dom.*;
import mlreportgen.report.*
ID = [1;2;3;4;5];
Name = {'San';'John';'Lee';'Boo';'Jay'};
Index1 = [1;2;3;4;5];
Index2 = [176.23423;163.123423654;131.45364572;133.5789435;119.63575647];
Index3 = [176.234;16.123423654;31.45364572;33.5789435;11.6647];
p = table(ID,Name,f(Index1),f(Index2),f(Index3));
V = #(x) inputname(1);
p.Properties.VariableNames(3:end) = {V(Index1), V(Index2), V(Index3)};
headerStyle = { BackgroundColor("LightBlue"), ...
Bold(true) };
tableStyle = { Width("60%"), ...
Border("single"), ...
RowSep("solid"), ...
ColSep("solid") };
p = MATLABTable(p)
p.Style = headerStyle;
p.TableEntriesHAlign = 'center';
d = Document('myPDF','pdf');
d.OutputPath = ['E:/','temp'];
append(d,'Report for file: ');
append(d,p);
close(d);
rptview(d.OutputPath);
end
function FivDigsStr = f(x)
%formatting to character array with 5 significant digits and then splitting at each tab
FivDigsStr = categorical(split(sprintf('%0.5G\t',x)));
%Removing the last (empty) value (which is included due to \t)
FivDigsStr = FivDigsStr(1:end-1);
end
You defined the variable tableStyle in which you defined the desired properties but you didn't set them. Also instead of setting the header as bold and light blue background, you are setting all the entries to have that.
The following code fixes that:
set(p, 'Width', '60%', 'Border', 'single',...
'RowSep', 'solid', 'ColSep', 'solid',...
'TableEntriesHAlign', 'center');
p.HeaderRule = ''; %To remove the underlining of header entries
p.Header.Style = headerStyle; %Setting the Header Style
I have the following table structure in MATLAB:
Year Month datapoint
1990 1 5
1990 2 7
.
.
.
1995 12 3
I want to plot this with datapoint on y-axis and something like 1990_1, 1990_2... on the x-axis.
How can I go about doing this?
You can format the appearance of the XAxis by getting the handle to that object with the get function, and then modifying the properties directly.
% Create example table
t = table();
t.Year = repelem(1990,72,1);
t.Month = [1:72].';
t.datapoint = [5:76].';
plot(t.datapoint)
% Get x axis
xaxis = get(gca,'XAxis');
% Format tick labels
xaxis.TickLabels = compose('%d_%d',t.Year,t.Month);
% Format interpreter
xaxis.TickLabelInterpreter = 'none';
% Limit number of ticks
xaxis.TickValues = 1:numel(t.datapoint);
As per your comment, to only see every 12th label:
indx = 1:72;
indx(12:12:72) = 0;
indx(indx > 1) = 1;
xaxis.TickLabels(find(indx)) = {''}
I want to create a dataset of my own like CIFAR-10 but not with RGB values but CEDD feature vector of image. I am creating a imageDatastore and reading the images and thier labels with following code :
imageFolder = fullfile('G:\9th Semester\Project - 2\myDataset');
imds = imageDatastore(imageFolder,'LabelSource', 'foldernames', 'IncludeSubfolders',true);
[trainingSet , testingSet] = splitEachLabel(imds , 0.8 , 'randomize');
trainingSet = shuffle(trainingSet);
testingSet = shuffle(testingSet);
data = [];
labels = char.empty(0,10);
cedd = [];
for i=1:size(trainingSet.Files)
image = readimage(trainingSet,i);
cedd = CEDD(image);
zerosCount = 0 ;
for j=1:144
if cedd(j) == 0
zerosCount=zerosCount + 1;
end
end
if zerosCount ~= 144
data(i , :) = cedd;
labels(i ,: ) = trainingSet.Labels(i);
end
end
save('train.mat' , 'data' , 'labels');
But is giving me this error :
Unable to perform assignment because the size of the left side is 1-by-10 and the size of the right side is 1-by-3.
Error in dataset (line 20)
labels(i ,: ) = trainingSet.Labels(i);
Any help will be much appreciated !
In matlab, I have a bunch of stored lines that are just vertical in an array called H, like so:
h(1)=plot([10,10][750,1000])
h(2)=plot([20,20][750,1000])
h(3)=plot([30,30][750,1000])
I know that to delete the second plot, i would do: delete(h(2)) followed by h(2)=[]. The problem is, I don't know the index of 20. Let's say I have the number 20 stored, is there a way to get the location of my vector h where there is a line with an x value of 20 to delete?
You can do it as follows:
h(2).XData(20) = [];
h(2).YData(20) = [];
Example:
X = 1:5;Y = 1:5;
h = plot(X, Y, 'o');grid on;
h.XData(3) = [];h.YData(3) = [];