matlab legend dotted lines

조회 수: 21 (최근 30일)
venkat siddhartha rama
venkat siddhartha rama 2020년 1월 8일
댓글: venkat siddhartha rama 2020년 1월 9일
Hello friends,
I have a problem with matlab plotting. My plot has 10 curves, I use legend to represent them,but legend only used 7 colours,after 7 colours, it repeats the colours...which is confusing to fing the plot curve needed. I have attached screenshot of the plot, there are two blues in the curve,which is hard to find the needed curve. Is there any way to get through this problrm ..like have dotted lines after 7 curves or have the values of the curves right next to the curve as shown in the exaple plot. I have attached example curve next to the plot screen shot. In the example plot, the value of the curve is right next the curve, that is actually very easy to navigate through the plot. I am looking forward to hear anything..Thak you all..
This is the code that I used to get the curve:
figure
plot(KW_of_solar_panel,Solar_Optimization_total_Price)
xlabel('SOLAR NAME PLATE CAPACITY (KW) ')
ylabel('TOTAL PRICE IN PRESENT DAY DOLLARS ($)')
%title('Solar Name Plate Capacity VS Solar optimization total prize in present day dollars')
plot1_Increment1=sprintf(' WIND TURBINE CAPACITY = %0.3d KW',no_of_wind_turbines(1,1)*Turbine_rated_power);
plot1_Increment2=sprintf(' WIND TURBINE CAPACITY = %0.3d KW',no_of_wind_turbines(2,2)*Turbine_rated_power);
plot1_Increment3=sprintf(' WIND TURBINE CAPACITY = %0.3d KW',no_of_wind_turbines(3,3)*Turbine_rated_power);
plot1_Increment4=sprintf(' WIND TURBINE CAPACITY = %0.3d KW',no_of_wind_turbines(4,4)*Turbine_rated_power);
plot1_Increment5=sprintf(' WIND TURBINE CAPACITY = %0.3d KW',no_of_wind_turbines(5,5)*Turbine_rated_power);
plot1_Increment6=sprintf(' WIND TURBINE CAPACITY = %0.3d KW',no_of_wind_turbines(6,6)*Turbine_rated_power);
plot1_Increment7=sprintf(' WIND TURBINE CAPACITY = %0.3d KW',no_of_wind_turbines(7,7)*Turbine_rated_power);
plot1_Increment8=sprintf(' WIND TURBINE CAPACITY = %0.3d KW',no_of_wind_turbines(8,8)*Turbine_rated_power);
plot1_Increment9=sprintf(' WIND TURBINE CAPACITY = %0.3d KW',no_of_wind_turbines(9,9)*Turbine_rated_power);
plot1_Increment10=sprintf(' WIND TURBINE CAPACITY = %0.3d KW',no_of_wind_turbines(10,10)*Turbine_rated_power);
legend(plot1_Increment1,plot1_Increment2,plot1_Increment3,plot1_Increment4,plot1_Increment5,plot1_Increment6,...
plot1_Increment7,plot1_Increment8,plot1_Increment9,plot1_Increment10);
set(legend,'location','best')
First blue curve is when wind turbine capacity is at 0 KW,
next red curve is when wind turbine capacity is at 12000KW
and so on...I just want to have a text or something that says that says blue line is so and so at the end of the curve with out legend as Looking at colour in legend and finding that coloured curve on plot is tricky. That is exactly what has been done in Example curve,10,15,25,... bph are properties of the respective curve but are not a part of plotting as in x and y axis variable.
Example Plot:

답변 (1개)

Allen
Allen 2020년 1월 8일
편집: Allen 2020년 1월 8일
Without knowing whether your x and y inputs used in the plot function are vectors or arrrays it is hard to derive a working solution. However, by taking a quick attempt you can try replacing the line containing plot(KW_of_solar_panel,Solar_Optimization_total_Price) with something similar to the following.
plot(KW_of_solar_panel(:,1:7),Solar_Optimization_total_Price(:,1:7))
hold on
plot(KW_of_solar_panel(:,8:end),Solar_Optimization_total_Price(:,8:end),':')
The ':' notation following a specific entry or group of entries in plot() will create a dotted line.
Additionally, the user created function at the following link can be used to generate n-distinct colors which can in turn be used to define colors of each line in the plot. The user has provided instructions on how to use this function as comments within the code.
  댓글 수: 3
Allen
Allen 2020년 1월 9일
편집: Allen 2020년 1월 9일
MATLAB does have a built-in text label function; however, I am not familiar enough with it to be of much help. Checkout the annotations section at the following site.
From the array sizes that you provided, replacing the plot functions with the following code might work.
plot(KW_of_solar_panel,Solar_Optimization_total_Price(:,1:7))
hold on
plot(KW_of_solar_panel,Solar_Optimization_total_Price(:,8:end),':')
I have also posted a function on file exchange that replaces default data tips with a draggable version, which has a custom label option to identify the line that was targeted. The labels used are the DisplayNames from the plot legend. In a pinch this might work for you, but would require manually adding a data tip to each line. If you think it might be worthwhile, checkout the provided link. Notes for usage are in the function comments.
venkat siddhartha rama
venkat siddhartha rama 2020년 1월 9일
Thank you, Dotted lines are working good...but I still couldn't figur out how to name the curves without having legend as in example figure. 10,15,20...bph are properties that lead to x and y values to get the respective curves. That would be very helpful to go through the plot instead of looking for colour in legend and searching for the respective coloured curve in plot...

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Wind Power에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by