using a viridis colormap

Hello everyone,
I would like to know how is it possible to use properly a viridis colormap in order to draw scatter figures. For instance, i have this figure to plot :
figure(2)
plot(x1,y1,'^r','MarkerSize',8,'MarkerFaceColor','r')
% plot(x1,y1,'^r','MarkerSize',8,'MarkerFaceColor',viridis(5))
xlabel('F_{vis}')
ylabel('F_{flambement}','FontSize',13)
But I don't know how to use this "alternative" colormap since I am not familiar with this function in this case.
Could someone help please ?
Thank you in advance.
Sincerely.

 Respuesta aceptada

Image Analyst
Image Analyst el 21 de Feb. de 2022

1 voto

See attached demos where I show you how you can replace the default color order of plots and markers with some custom colormap of your own creation.

1 comentario

Nidia Maldonado Carmona
Nidia Maldonado Carmona el 28 de Mzo. de 2022
Thanks a lot for this! This has been really helpful!

Iniciar sesión para comentar.

Más respuestas (2)

DGM
DGM el 21 de Feb. de 2022
Editada: DGM el 21 de Feb. de 2022
Use scatter() instead of plot(). The behavior of viridis() is otherwise the same as the built-in functions like jet().
N = 20;
x1 = randn(N,1);
y1 = randn(N,1);
scatter(x1,y1,50,viridis(N),'filled','^')

5 comentarios

Wissem
Wissem el 21 de Feb. de 2022
@DGM I may have missed something because I got an error when I typed the line :
scatter(x02,y02,viridis(5),'filled','d')
What's wrong with that ?
Thanks
Stephen23
Stephen23 el 21 de Feb. de 2022
Editada: Stephen23 el 21 de Feb. de 2022
"What's wrong with that ?"
The SCATTER documentation shows that if the 1st and 2nd arguments are X and Y values then the 3rd argument must be the marker size (which you did not provide). The 4th argument is the marker color (not 3rd like you tried).
Also VIRIDIS is not inbuilt. Did you download VIRIDIS from here:
and unzip the ZIP file onto your MATLAB path, before trying to use it?
DGM
DGM el 21 de Feb. de 2022
As Stephen says, you're missing the marker size specification in the call to scatter().
Wissem
Wissem el 21 de Feb. de 2022
Yes you are right : I totally missed this argument. However, I am still unable to use this command since the viridis function is not recognized despite the fact that it's added to my current path. I don't understand why it doesn't work : I am going to check again for the path directory.
Stephen23
Stephen23 el 21 de Feb. de 2022
@Wissem-Eddine KHATLA: you can also place it into the current directory, which may be easier.

Iniciar sesión para comentar.

Wissem
Wissem el 23 de Feb. de 2022

0 votos

Thank you all for your help : I really got what I was looking for !
Thanks again !

Categorías

Más información sobre Color and Styling en Centro de ayuda y File Exchange.

Preguntada:

el 21 de Feb. de 2022

Comentada:

el 28 de Mzo. de 2022

Community Treasure Hunt

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

Start Hunting!

Translated by