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 (한국어)