이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
3D plot including different colors
조회 수: 5 (최근 30일)
이전 댓글 표시
Hi,
I'd like to create a 3-D Chart and be able to manipulate the axis in order to see the Dates. the code I completed so far is the following:
myDates=[735845;735846;735847;735850;735851;735852;735853;735854]
stock1=[100;98;102;110;108;122;140;145]
stock2=stock1.*1.1;
stock3=stock2.*1.2;
myStocks=[stock1 stock2 stock3];
myData=[myDates stock1 stock2 stock3]
surf(myStocks)
What I am doing is plotting 3 different stock Price paths and I would like to add the corresponding date on the x-axis and in Addition, be able to rotate the Chart, so that the first line of the plane is stock1, then stock2 and one in the back is stock3. I would also like to have the first value of stock1 on the left side and the last value on the right side so the curve is upward sloping from left to right in this case and also from front to back.
thanks a lot for your supprt.
채택된 답변
Star Strider
2014년 11월 16일
myDates=[735845;735846;735847;735850;735851;735852;735853;735854];
stock1=[100;98;102;110;108;122;140;145];
stock2=stock1.*1.1;
stock3=stock2.*1.2;
stox = [stock1 stock2 stock3];
figure(1)
ribbon(myDates,stox)
datetick('y', 'yyyy-mm-dd')
set(gca, 'FontSize',8)
댓글 수: 23
Locks
2014년 11월 16일
I tried it with your code but the plot only consists of black lines. Is there anything I can do in order to get a plot with different Colors and not only with black lines?
Star Strider
2014년 11월 16일
It should plot with different colours by default.
Setting:
view([-140 50])
and with no other changes in the code I posted, I get this in R2014b:
See if rotating yours changes its behaviour.
Locks
2014년 11월 16일
You're right, the Problem is that my example was to simplistic. The actual dataset I have consist of around 300 columns which I do have to plot and is looking more like the following:
myDates=[735845;735846;735847;735850;735851;735852;735853;735854];
stock1=[100;98;102;110;108;122;140;145];
stock2=[NaN;101;105;107;103;100;120;180];
stock3=[NaN;NaN;NaN;130;125;147;145;150];
stocks = [stock1 stock2 stock3];
Is it possible, that over 300 data series are just too many? is there any other possibility?
Star Strider
2014년 11월 16일
That many data are too much for ribbon to show as discrete bands with colours. You might try:
figure(1)
mesh(stocks)
tklbls = cellstr(datestr(myDates,'yyyy-mm-dd'));
set(gca, 'YTickLabel',tklbls)
% datetick('y', 'yyyy-mm-dd')
set(gca, 'FontSize',8)
but you might not get any better resolution with it.
Locks
2014년 11월 17일
thank you very muuch!
does look much better, however there is s Problem with the Dates, my Dates vector goes from 20-Nov-1989 to 21-Oct-2014
I changed the Format to:
tklbls = cellstr(datestr(myDates,'mmmyyyy'));
But I get displayed only Nov 1989 8 times on the axis, there seems to be an issue with the Dates, any idea what it could be?
Star Strider
2014년 11월 17일
My pleasure!
When I run it (in R2014b) with your most recent data, I get the dates displaying as they should:
It looks strange because of the NaN values, but the dates display normally. Are you using the same vector of dates that you posted previously?
In this plot, I’m using:
myDates=[735845;735846;735847;735850;735851;735852;735853;735854];
Locks
2014년 11월 17일
I used the myDates vector only as a dummy, I have around 20 years of daily data. When I do the plot, the data Looks good, but there seems to be sth. stranges with the Dates Happening. the variable tklbls saves data from 'Nov1989' to 'Oct2014', which is exactly what I Need, however it is displayed falsely as you can see in the figure.
the code I am using is the following (only small adjustements to your Version):
myDatesClose=dataFinalPriceClose(:,1);
mesh(dataFinalPriceClose(:,2:end))
%tklbls = cellstr(datestr(myDates,'yyyy-mm-dd'));
tklbls = cellstr(datestr(myDatesClose,'mmmyyyy'));
Star Strider
2014년 11월 17일
Attach a representative sample of ‘dataFinalPriceClose’. it could be the problem.
Locks
2014년 11월 17일
I have attached it. the complete datasaet consists of 6089 rows (days) and 361 columns (first one is the date and 2:361 are dataseries). Does this help?
Star Strider
2014년 11월 17일
What the HG2 graphics in R2014b lack in the flexibility that handle graphics had in previous releases, they more than make up for in frustration.
I’ve been working for at least the past two hours attempting to get both the the dates and data to plot correctly. If the dates plot correctly, the data do not plot at all, and if the data plot correctly, the dates either do not plot correctly or do not plot at all. What probably would have been a 15-minute (and quickly successful) solution in earlier versions is now impossible. I’ve tried to meshgrid the dates and every possible combination of handle graphics tricks I can think of. The only solution that worked plotted the dates so densely they were impossible to read (although I can’t claim that the dates plotted correctly then, because even zooming couldn’t distinguish them). When I tried to use the new datetime functions with meshgrid dates (so I could put them in the mesh statement), the code threw an error, telling me:
There is no DateTimeTickFormat property on the Surface class.
What you want to do is likely not possible in R2014b. If it’s any consolation, you’re in good company. It seems several options that were possible previously are now not at all possible.
I suggest you contact Tech Support to see if they have a solution. If they do, please post it here. I’d like to know what they come up with.
Locks
2014년 11월 18일
편집: Locks
2014년 11월 18일
thanks a lot for your effort!
I am acutally using R2012a, does that Change anything? Do you by any Chance know a solution that should work there?
I just checked on the webside and I guess due to the fact I am using a Student Version only, I will not get any help from tech. Support (<http://ch.mathworks.com/support/contact_us/>)
Star Strider
2014년 11월 18일
편집: Star Strider
2014년 11월 18일
If you’re using R2012a, anything with R2014a should also apply. I’ve not uninstalled it, so I’ll see if the ideas I couldn’t apply in R2014b will work in R2014a. I’ll edit this Comment and post my solution if it works.
————— EDIT —————
Apparently you can only have 5 ticks on your y (dates) axis. If I attempt to override it with the set(gca, 'YTick', dv) command with or without specifying 'YTickLabel' it simply refuses to display anything. Zooming displays more tick labels, but for some reason, it’s impossible to set them in a surface plot.
Using the file you uploaded:
[d,s,r] = xlsread('Locks_dataSample.xlsx');
qd = d(:,2:end);
dcm = 1:fix(size(qd,1)/4):size(qd,1); % Five Date Tick Values
dv = d(dcm,1);
figure(1)
mesh(qd)
xlabel('Stock')
ylabel('Time')
tklbls = cellstr(datestr(dv,'yyyy-mm-dd'));
set(gca, 'YTickLabel',tklbls)
view([60 30])
That seems to be as good as it gets.
Locks
2014년 11월 18일
sorry one additional Thing, I tried to copy the figure into a word document, but it is not working because the figure is too large. I tried to save it as a pdf, this did work but there are some black spots on it. Is there a any way to copy paste this figure into word?
Star Strider
2014년 11월 18일
My pleasure!
Unfortunately, I don’t have any recent experience exporting figures into Word. There’s a File Exchange contribution exportfig that might help do what you want. It’s popular and well-reviewed.
Locks
2014년 11월 22일
sorry, I was quite busy lately and therefore it took me so Long to have a look at it. thanks a lot, I will try it.
Star Strider
2014년 11월 22일
My pleasure! There may be other possibilities, but everyone seems to like ‘export_fig’.
Locks
2014년 11월 22일
I downloaded the file and saved it in the same Folder where my srcipts are, but if I run the function I get the error "Undefined function 'export_fig' for input arguments of type 'char'." I expect there is something wrong about how I saved it, but I found nothing on in the readme https://github.com/ojwoodford/export_fig/blob/master/README.md
any idea what I need to change?
Star Strider
2014년 11월 22일
It’s a .zip file. Did you unzip it into its own subdirectory and then use addpath to add it to your search path? MATLAB needs to know that it exists and where to find it.
Locks
2014년 11월 22일
I added the path, saving is fine but I haven't been able to copy paste it into a word document. is seems to me as the figure is just too large. but that's fine, I guess trying to plot more than 20 years of daily data from different contracts is just a bit too much, I will see what I can do.
Star Strider
2014년 11월 22일
I can’t suggest anything other than perhaps printing it on B0 paper! Otherwise, you may have to sacrifice some detail to print it on A4 or similar.
It may be worthwhile to search Answers for ‘exportfig’, ‘export_fig’, or other spellings, since others have likely encountered similar situations and tweaked its settings to produce detailed plots of acceptable quality.
Locks
2014년 11월 23일
I tried to make a pdf but it Looks awful. there are some black spots on the graphics, but I will try to find out more about Export_fig.
Thanks a lot for your help!
Star Strider
2014년 11월 23일
My pleasure!
Also, search Kelly Kearney’s answers. She’s dealt with a some of these problems and her posts might yield some clues on how to do what you want.
추가 답변 (0개)
참고 항목
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
아시아 태평양
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)