Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I want to get my time series plot in the form of second plot below. But I do not know how this bar chart in MATLAB can be obtained for a series time. Has anyone ever had such an experience to guide me? The first figure is an example of a time series plot that I want to plot in the form of the second plot.
It should be noted that the first image is with a simple plot command in MATLAB.
http://www.sidc.be/silso/datafiles#total
link address for data.i plot a daily data of sunspot number from the link that it's like the first curve here. now i want to have a curve like the second pic here for any time series data.
You can make a stacked bar chart with two different sets of bars, then make the bottom bar white so it is invisible, then the top sets of bars will look like your above plot. Here is some sample code and the plot it makes
bar_bottom = [0.5, 2, 1.5];
bar_height = [4, 5, 3];
x = 1:3;
h = bar(x, [bar_bottom; bar_height], 'stacked');
set(h(1),'EdgeColor', 'w', 'FaceColor', 'w') % set bottom bar to be white (invisible since background is white)
set(h(2),'FaceColor', 'c', 'EdgeColor', 'w', 'BarWidth', 1)
line(x, bar_bottom + 0.5 * bar_height, 'LineWidth', 2)
Related
This question already has answers here:
Getting a second row of xlabels in matlab graph?
(1 answer)
add data label to a grouped bar chart in matlab
(1 answer)
Closed 7 months ago.
I have two types of plots.
In fist case I need to label individual bar graphs in the grouped bar plot. Here is the example
a=4.54,88.63,27.27,77.27,54.54;31.81,61.36,38.63,68.18,54.54;54.54,61.36,59.09,54.54,50;68.18,27.27,56.81,34.09,50;90.90,11.36,68.18,15.90,40.90];
b=0.40,0.55,0.70,0.85,1;1.39,1.54,1.69,1.84,1.99;2.340,2.49,2.64,2.79,2.94;3.36,3.51,3.66,3.81,3.96;4.29,4.44,4.59,4.74,4.89];
figure,
hold on
for i=1:5
bar(b(i,:),a(:,i))
end
figure,
hold on
for i=1:3
plot(b(i,:),a(:,i))
end
For the bar plot, I like to lable on the horizontal as shown in figure, the numbers are stored in an other matrix, say b
2) Similarly, I also want to XTickLables using values in b for the line plot.
you have first to define xticks and XTickLables
for example you can write:
a=[....];
b=[....];
c=[0.5,1,1.5,2,3];
D = {'0.5','1','1.5','2','3'};
figure,
hold on
for i=1:5
bar(b(i,:),a(:,i));
xticks(i) = c(i); %% first you define the ticks
XTickLables{i} = d(i); %% second you define the labels
end
for the exact same plot like the one you showed, I think you need two nested for loops.
more on that here: https://de.mathworks.com/help/matlab/ref/xticklabels.html
This question already has answers here:
Show two different plots in one plot
(2 answers)
MATLAB - Plot multiple data sets on a scatter plot
(3 answers)
Closed 3 years ago.
I have a heat map of values generated by "pcolor" in MATLAB. I would like to plot a line plot on top of that.
I haven't found a proper solution in any measure yet.
The following code generates a "heat map" sort of output
hc = pcolor(middle_long, middle_height, middle_no2);
set(hc, 'Edgecolor', 'none');
c = colorbar;
caxis([0 0.015]);
axis([min(middle_long(:,1)) max(middle_long(:,1)) 0 1000])
The following code generates a line plot
plot(longflag, hflag)
The following are figures of the individual plot types that I would like to join, with an "example" of the final product I'd like listed afterwards:
Try something like this. Note the hold on part, which prevents plot from deleting the image produced by pcolor:
pcolor(rand(10))
colormap bone
axis xy
hold on
plot([1 10], [10 1], 'r')
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I'm trying to make a confusion matrix for some classification problem.
So far, I've managed to make a 10 by 10 matrix that stores the accuracy of my estimation for classification problem.
Now I want to make a 10 by 10 square image(?) that has a darker color when the number in that location of the matrix has a higher number. (Ranges from 0 to 100)
I've never done graphics with Matlab before.
Any help would be greatly appreciated.
Thanks.
I would use image. For example:
img = 100*rand(4,4); % Your image
img = img./100*64; % The `image` function works on scale from 0->64
image(img); % or `image(img')` depending on how you want the axis
colormap('grey'); % For grey scale images
axis equal; % For square pixels
Or for inverted colours you can change the one line to:
img = 64-img./100*64;
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I have seen a plot in one page. I wanted to recreate a similar plot I searched for the code but could not find the code for the plot. Attaching the plot with this of which I wanted to generate in MATLAB
As an example, here's a plot for a dampened sine curve:
A=10;
f=1000;
n=5;
T=1/f;
t=[0:T/100:n*T];
s=A*exp(-t*1000).*sin(2*pi*f*t);
% Here is the bit you'd be interested in:
plot(t,s,'b-','lineWidth',2) %'b-' is blue line.
xlabel('time (s)')
ylabel('amplitude (v)')
set(gca,'linewidth',2)
grid on
ax = gca;
ax.XGrid = 'off';
ax.YGrid = 'on';
set(ax,'GridLineStyle','--')
Change the formula or data to achieve desired plot shape.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Please If anyone can give a hint on drawing this in matlab
( I am not asking for the actual code but just a hint....)
Hard do give a hint, as it is just one line of code.
rectangle('Position',[1,2,5,6])
To actually see the rectangle you need to set the axes limits:
axis equal
xlim([0,8])
ylim([0,9])
Regarding your comment: have a look at this answer which gives a little introduction into the core graphics objects you're lookling for.
Core Graphics Objects
Core graphics objects include basic drawing primitives:
Line, text, and polygon shells (patch objects)
Specialized objects like surfaces, which are composed of a rectangular grid of vertices
Images
To draw an arbitrary figure you can use plot. For example, this draws a trapezoid:
x = [1 7 4 2 1]; %// x coordinates of vertices
y = [1 1 3 3 1]; %// y coordinates of vertices
plot(x,y); %// do the plotting
axis([0 8 0 4]) %// set axis limits
As you se, you specify the vertices and plot (in its default behaviour) joins them with straight lines. You need to specify the first vertex again as a last vertex to close the polygon.