Non Transparent Text Background on Candlestick Chart
조회 수: 1 (최근 30일)
이전 댓글 표시
Hello! I wonder if it is possible to plot the text with the background over the candlestick chart in such a way that the candles beneath the text background are covered and not vice versa. I am not sure how this can be done. I hope there is a way around this!) Thanks!)
here is the example price data:
28.11.2000 156.37 157.28 155.82 156.34
29.11.2000 156.09 158.73 155.86 158.34
30.11.2000 158.26 158.53 156.79 157.51
01.12.2000 157.29 160.91 156.99 160.51
04.12.2000 160.42 161.97 159.52 161.17
05.12.2000 161.16 161.75 158.93 159.29
06.12.2000 159.2 159.79 158.33 159.3
07.12.2000 159.1 160.57 158.78 159.75
08.12.2000 159.68 161.76 159.32 161.13
11.12.2000 161.59 161.79 159.76 161.32
12.12.2000 161.14 162.3 160.75 161.51
13.12.2000 161.33 164 161.13 163.73
14.12.2000 163.42 165.67 163.34 164.85
15.12.2000 164.7 166.54 164.65 166.02
18.12.2000 165.73 166.73 163.85 165.74
19.12.2000 165.51 165.83 163.57 165.13
20.12.2000 165.04 166.98 164.82 166.62
21.12.2000 166.4 167.16 164.62 165.41
22.12.2000 165.23 167.44 164.92 166.28
25.12.2000 166.12 167.64 166.07 166.95
26.12.2000 166.98 168.93 166.7 168.76
27.12.2000 168.48 171.35 168.25 170.91
28.12.2000 170.82 171.71 170.23 170.84
29.12.2000 170.79 171.99 170.49 170.98
02.01.2001 171.15 172.34 170.32 172.1
03.01.2001 171.88 172.93 168.96 169.64
04.01.2001 169.39 174.02 169.28 173.83
05.01.2001 173.6 175.84 173.42 175.4
08.01.2001 175.18 175.88 172.74 174.18
09.01.2001 173.88 174.42 172 174.17
10.01.2001 174 174.5 172.14 173.16
11.01.2001 172.95 176.83 172.89 176.64
12.01.2001 176.55 177.77 173.7 175.35
15.01.2001 175.02 176.59 174.88 175.87
Thanks!)
댓글 수: 0
답변 (1개)
SAI SRUJAN
2024년 7월 9일
Hi Dima,
I understand that you are facing an issue with plotting non transparent text background on candlestick chart.
Please go through the following code sample to understand how to plot text with a background over a candlestick chart in MATLAB, ensuring that the text background covers the candles beneath it.
% Sample data
dates = datetime({'28.11.2000','29.11.2000','30.11.2000','01.12.2000','04.12.2000',...
'05.12.2000','06.12.2000','07.12.2000','08.12.2000','11.12.2000',...
'12.12.2000','13.12.2000','14.12.2000','15.12.2000','18.12.2000',...
'19.12.2000','20.12.2000','21.12.2000','22.12.2000','25.12.2000',...
'26.12.2000','27.12.2000','28.12.2000','29.12.2000','02.01.2001',...
'03.01.2001','04.01.2001','05.01.2001','08.01.2001','09.01.2001',...
'10.01.2001','11.01.2001','12.01.2001','15.01.2001'}, 'InputFormat', 'dd.MM.yyyy');
open = [156.37 156.09 158.26 157.29 160.42 161.16 159.2 159.1 159.68 161.59 161.14 161.33 163.42 164.7 165.73 165.51 165.04 166.4 165.23 166.12 166.98 168.48 170.82 170.79 171.15 171.88 169.39 173.6 175.18 173.88 174 172.95 176.55 175.02];
high = [157.28 158.73 158.53 160.91 161.97 161.75 159.79 160.57 161.76 161.79 162.3 164 165.67 166.54 166.73 165.83 166.98 167.16 167.44 167.64 168.93 171.35 171.71 171.99 172.34 172.93 174.02 175.84 175.88 174.42 174.5 176.83 177.77 176.59];
low = [155.82 155.86 156.79 156.99 159.52 158.93 158.33 158.78 159.32 159.76 160.75 161.13 163.34 164.65 163.85 163.57 164.82 164.62 164.92 166.07 166.7 168.25 170.23 170.49 170.32 168.96 169.28 173.42 172.74 172 172.14 172.89 173.7 174.88];
close = [156.34 158.34 157.51 160.51 161.17 159.29 159.3 159.75 161.13 161.32 161.51 163.73 164.85 166.02 165.74 165.13 166.62 165.41 166.28 166.95 168.76 170.91 170.84 170.98 172.1 169.64 173.83 175.4 174.18 174.17 173.16 176.64 175.35 175.87];
% Plot candlestick chart
figure;
T = timetable(dates', open', high', low', close', 'VariableNames', {'Open', 'High', 'Low', 'Close'});
T = sortrows(T);
candle(T);
hold on;
% Define text position and content
% Change xPos, yPos as required.
xPos = 10; % Index of the x position for the text
yPos = 170; % Y position for the text
textContent = 'Sample Text';
% Plot rectangle for background
rectWidth = 5; % Adjust width as needed
rectHeight = 5; % Adjust height as needed
rectangle('Position', [xPos-rectWidth/2, yPos-rectHeight/2, rectWidth, rectHeight], ...
'FaceColor', 'white', 'EdgeColor', 'black');
% Plot the text on top of the rectangle
text(xPos, yPos, textContent, 'HorizontalAlignment', 'center', 'VerticalAlignment', 'middle');
% Improve the plot appearance
xlabel('Date');
ylabel('Price');
title('Candlestick Chart with Overlay Text');
grid on;
hold off;
For a comprehensive understanding of the 'rectangle', 'candle' and 'text' function in MATLAB, please refer to the following documentation.
I hope this helps!
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Bar Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!