Dracula color theme for figures
MATLAB functions for converting your figures into a stylish dark color theme.
"Dracula" is a very popular color theme used by programmers who prefer to do their work in dark mode. You can apply the Dracula color theme to your MATLAB Desktop application by following the instructions here, and a list of the Dracula color codes can be found at this link.
However, by default, MATLAB figures are generated with a white background and it can be a pain to manually change all of the object colors in your figures to make them fit your dark mode color preferences. But now, thanks to the functions in this collection, converting your figures into Dracula-themed colors is as simple as using one line of code --- just call the draculize function after creating a figure!
See the examples below to view how the draculize function works in action.
Basic Plots
The syntax for making your figures Dracula themed is easy. Simply create a plot as you would normally and then call the function draculize with no inputs or outputs.
x = linspace(0,4*pi,25);
y1 = sin(x).*rand(size(x));
y2 = sin(x).*rand(size(x))+0.3;
y3 = sin(x).*rand(size(x))+0.6;
y4 = sin(x).*rand(size(x))-0.4;
figure(1)
subplot(2,3,1)
plot(x,[y1' y2' y3' y4'],'LineWidth',2), axis square tight
title('Line Plot')
draculize
subplot(2,3,2)
scatter(x,[y1' y2' y3' y4'],'.'), box on, axis square tight
title('Scatter Plot')
draculize
subplot(2,3,3)
bar(x,[y1' y2' y3' y4'],1,'stacked'), axis square tight
title('Bar Plot')
draculize
subplot(2,3,4)
stairs(x,[y1' y2' y3' y4'],'LineWidth',1), axis square tight
title('Stairs Plot')
draculize
subplot(2,3,5)
area(x,[y1' y2' y3' y4']), axis square tight
title('Area Plot')
draculize
subplot(2,3,6)
piechart([10 12 31 16 11 6 14],'FaceAlpha',1,ExplodedW=3)
title('Piechart')
draculize
The draculize function also works on any basic plots that contain a title, subtitle, axes labels, a legend, added text, and grid lines. It also works for 3D plots.
figure(2)
contour3(peaks,50)
title('This is a title'), subtitle('This is a subtitle')
xlabel('X-axis'), ylabel('Y-axis'), zlabel('Z-axis')
hold on
text(0,30,-5,'This is added text.')
hold off
grid on
L=legend('Data','Location','northeast'); L.Title.String='Legend';
cb=colorbar; cb.Label.String='Colorbar';
draculize
Note that if you add a label, legend, etc. after executing the draculize function, the new object(s) will not be automatically incorporated into the Dracula theme. You will need to call the draculize function again in order to update the figure.
Color Order
If you don't want to convert the entire figure into the Dracula theme, but want to use Dracula colors for your data in place of the default MATLAB colors, then call the function dracula_colororder after creating your plot.
figure(3)
subplot(1,2,1)
plot(x,[y1' y2' y3' y4'],'LineWidth',2), axis square tight
title('Default Color Order')
legend('Y1','Y2','Y3','Y4')
subplot(1,2,2)
plot(x,[y1' y2' y3' y4'],'LineWidth',2), axis square tight
title('Dracula Color Order')
legend('Y1','Y2','Y3','Y4')
dracula_colororder
Color Map
A custom Dracula-themed color map (dracula_cmap) is available in the dracula.mat binary file. This color map is automatically applied to a figure when using the draculize function. However, if they user only wants to use the color map without applying the full Dracula theme to a figure then simply call the dracula_colormap function!
figure(4)
sc = surfc(membrane); sc(2).LineWidth=2; zlim([-1 1])
title('Dracula Color Map')
colorbar
dracula_colormap
Boxcharts and Histograms
Boxcharts only display as one color, unless you have grouped data. The same is true for histograms. In either case, the draculize function still works.
grp = [repmat("Y1",size(y1'));...
repmat("Y2",size(y2'));...
repmat("Y3",size(y3'));...
repmat("Y4",size(y4'))];
data = table(categorical(grp), [y1 y2 y3 y4]',...
'VariableNames',{'Group','Values'});
figure(5)
boxchart(data.Values,'GroupByColor',data.Group,'BoxWidth',0.8), box on, axis square
title('Boxcharts')
legend(categories(data.Group))
xticklabels('Data')
draculize
figure(6)
x1 = randn(2000,1);
x2 = 2.5 + randn(5000,1);
x3 = randn(3000,1) - 1.8;
x4 = randn(600,1) + 5;
h1 = histogram(x1,'Normalization','pdf');
title('Histograms')
hold on
h2 = histogram(x2,'Normalization','pdf');
h3 = histogram(x3,'Normalization','pdf');
h4 = histogram(x4,'Normalization','pdf');
legend('x1','x2','x3','x4')
hold off
set(gca,'YGrid','on')
ysecondarylabel('[PDF]'), xsecondarylabel('[X-Data]')
draculize
Polar Axes Charts
The draculize function is also compatible with charts generated in polar coordinates!
figure(7)
lw=2;
theta = 0:0.01:2*pi;
rho = sin(2*theta).*cos(2*theta);
for i = 1:7
j = [1.00 0.85 0.65 0.50 0.35 0.20 0.10];
polarplot(theta,rho.*j(i),'LineWidth',lw)
hold on
end
hold off
leg = repmat("\rho*",[7 1]) + string(num2str(j','%0.2f'));
L2=legend(leg); L2.Title.String='Legend';
draculize
引用格式
Austin M. Weber (2024). Dracula color theme for figures (https://www.mathworks.com/matlabcentral/fileexchange/157951-dracula-color-theme-for-figures), MATLAB Central File Exchange. 检索时间: .
MATLAB 版本兼容性
创建方式
R2023b
兼容任何版本
平台兼容性
Windows macOS Linux标签
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!