Making plots look beautiful
248 ビュー (過去 30 日間)
古いコメントを表示
Hi, I made a plot which displays the condition of cars of a particular brand overtime.
What i would like to do is to make the plot beautiful in apperance for presentation. I tried movmean, smoothing, choosing larger time intervals to avoid the jittering of the data points. But none of them helped me. Can anyone suggest me an idea on how to get this done?
Plot is attached
6 件のコメント
madhan ravi
2019 年 2 月 14 日
編集済み: madhan ravi
2019 年 2 月 14 日
I meant if OP is concerned about appearance!
Bjorn Gustavsson
2019 年 2 月 15 日
OP had a discrete counting-number data-set that was sampled at discrete times, and not with discretization noise. That's what the graph should present, in as clear and neat way as possible. Using smoothing or spline interpolation hides that data, even though the curves might look neater.
採用された回答
Luna
2019 年 2 月 14 日
編集済み: Luna
2019 年 2 月 14 日
Hello Hari,
I have just created a dummy data and plot them for you. You must check the line properties in documentation here the link:linespec
Please read comments carefully:
%% some random integer arrays 10x1
carsShowRoom = randi(20,10,1);
onRoad = randi(20,10,1);
good = randi(20,10,1);
bad = randi(20,10,1);
%% Time vector 1x10
time = 1:10;
figure;
hold on; % holds the axes
hPlot1 = plot(time,carsShowRoom); % hPlots are the plot handles, you can either change the properties from the handle object of the line or you can define them inside the plot function with 'propertyname',value pairs.
hPlot2 = plot(time,onRoad);
hPlot3 = plot(time,good);
hPlot4 = plot(time,bad);
hPlot1.LineStyle = '--'; % changes the line style
hPlot1.LineWidth = 2; % changes the line Width, you can get thin lines as you wish.
set(hPlot1, 'Marker', 'o'); % you can also use set function to set a property, definetely works like above. Marker adds a marker with shape you put. All of these informations are in the linespec link.
hPlot1.MarkerSize = 10;
hPlot1.MarkerEdgeColor = [0.85 0.47 0.32]; % Marker outside boundaries color
hPlot1.MarkerFaceColor = [0.1 0.25 0.89]; % Marker inside filling color
%% Note: To make your plot look beautiful use smooth colors not the defined 'r','b','c' colors they are way too bright.
% You can also use RGB color codes you can find on the internet but just be sure that Matlab gets color codes from 0 to 1 and RGB codes from 0 to 255. So you should interpolate it.
% For ex:
ColorCode = [148 130 78]./255; % Dividing 255 gives you the 0-1 value.
hPlot2.Color = ColorCode;
hPlot1.Color = 'c'; % As I said above don't use these bright colors.
%% Another important note:
% You can also use get method to see what properties and methods are defined for the line object
get(hPlot1)
%% gives you the below result:
AlignVertexCenters: 'off'
Annotation: [1×1 matlab.graphics.eventdata.Annotation]
BeingDeleted: 'off'
BusyAction: 'queue'
ButtonDownFcn: ''
Children: [0×0 GraphicsPlaceholder]
Clipping: 'on'
Color: [0 0.4470 0.7410]
CreateFcn: ''
DeleteFcn: ''
DisplayName: ''
HandleVisibility: 'on'
HitTest: 'on'
Interruptible: 'on'
LineJoin: 'round'
LineStyle: '-'
LineWidth: 0.5000
Marker: 'none'
MarkerEdgeColor: 'auto'
MarkerFaceColor: 'none'
MarkerIndices: [1 2 3 4 5 6 7 8 9 10]
MarkerSize: 6
Parent: [1×1 Axes]
PickableParts: 'visible'
Selected: 'off'
SelectionHighlight: 'on'
Tag: ''
Type: 'line'
UIContextMenu: [0×0 GraphicsPlaceholder]
UserData: []
Visible: 'on'
XData: [1 2 3 4 5 6 7 8 9 10]
XDataMode: 'manual'
XDataSource: ''
YData: [7 10 16 3 3 6 11 20 15 7]
YDataSource: ''
ZData: [1×0 double]
ZDataSource: ''
You can also add legend and change legend location, orientation, etc... See that link: legend
I hope all these informations are useful. Just try this with running each line one by one in debug mode and see what changes in your plot figure. So you can change every property and decide what looks beautiful.
Additional Edit:
-You can use grid, xlabel and ylabel (with editing their font size, font color and font type, etc...).
-To save your figure with high resolution (I am telling this because the plot you attached has a very low resolution-you can see what I plotted below), use File Menu left top of the figure and save as .png format for high resolution to use in your MS Office.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/204145/image.png)
If you still have any other questions, I can help.
5 件のコメント
Luna
2019 年 2 月 14 日
what is your leg variable? You should define it with a cell array and you must have N elements in the cell array where N is the number of your plot lines.
leg = {'line1','line2','line3'};
legend(leg,'Orientation','horizontal','Location','SouthOutside');
See this example in the documentation of legend:
x = linspace(0,pi);
y1 = cos(x);
plot(x,y1)
hold on
y2 = cos(2*x);
plot(x,y2)
y3 = cos(3*x);
plot(x,y3)
y4 = cos(4*x);
plot(x,y4)
hold off
legend({'cos(x)','cos(2x)','cos(3x)','cos(4x)'},'Location','northwest','NumColumns',2)
その他の回答 (2 件)
Bjorn Gustavsson
2019 年 2 月 14 日
You shouldn't manipulate your data that way. Your counting data is statistically "perfect" so you have to treat it as such, you could try to plot the data in different ways. Perhaps using stairs, or plot without the line:
plot(t_obs,car_data,'.','markersize',18)
Or take a look at some examples with bar-graphs...
HTH
4 件のコメント
Luna
2019 年 2 月 14 日
I think bar graph or histogram is not suitable because he wants to see the data change in time.
Bjorn Gustavsson
2019 年 2 月 15 日
What? Bar graphs can do that:
bar(t,car_locations,1,'stacked','edgecolor','none')
atharva aalok
2021 年 10 月 17 日
編集済み: atharva aalok
2021 年 10 月 17 日
Please refer the following Plotting Template:
The above is an easy to follow Beginner Friendly template.
The idea is to create Professional Standard Plots within seconds without a steep learning curve and with consistency.
It also offers a wide range of preset Color Codes (please refer the attached image for the Color Palatte)
Sample Plot:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/769911/image.png)
Color Palatte:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/769871/image.png)
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Specifying Target for Graphics Output についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!