Convert days and months in french for an axis of type DateTimeRuler

6 visualizaciones (últimos 30 días)
Hello,
I try to change language/locale for labels of axis of type DateTimeRuler with set(0,'Language',"fr_FR") without success ! Is ther another solution ?

Respuesta aceptada

Shivam Gothi
Shivam Gothi el 23 de Nov. de 2024
As per my understanding, you are trying to show the labels of axis containing "datetime" data in "French" language. There is no direct way to achieve the objective, but I found few workarounds which may help to resolve your question.
1) You can change the output dates to any user-preferred Locale
use Locale option from preferences (Preferences -> Command Window -> Datetime format -> Locale). If you can not see a particular Locale in a drop down menu, just type in there and apply the changes. It will accept it if you type in correctly. For example, if you want the output to be displayed in French, type the Locale as "fr_FR" and apply the changes. You will observe the output from "datetime" function displayed in German
2) You can use "cellstr" function to specify the "locale" property as demonstrated below:
%C = cellstr(D,'fmt',"fr_FR") %fmt = output format of datetime object (D)
Refer to the documentation to find more information about the function:
I have also illustrated its use by a small example as shown below:
%create an array of datetime object for demonstration purpose
year=2024+ones(1,6);
month= [1 2 3 4 5 6];
day=13+ones (1,6);
datearr =datetime(year, month, day)
datearr = 1x6 datetime array
14-Jan-2025 14-Feb-2025 14-Mar-2025 14-Apr-2025 14-May-2025 14-Jun-2025
C=cellstr(datearr,'MMM d, yyyy',"fr_FR") %you can specify any datetime format "fmt". Here, it is 'MMM d, yyyy'
C = 1x6 cell array
{'janv 14, 2025'} {'févr 14, 2025'} {'mars 14, 2025'} {'avr 14, 2025'} {'mai 14, 2025'} {'juin 14, 2025'}
%create data for y-axis (for demonstration)
y_data=[1 2 3 4 5 6];
A=plot(datearr,y_data);
A.Parent.XTickLabel=C;
As seen, the xlabels are now appearing in French language. I hope this answers your question !
  2 comentarios
Laurent Fritz
Laurent Fritz el 23 de Nov. de 2024
Thanks a lot, the first solution is best for my needs in order to be able to continue zooming xaxis.
Shivam Gothi
Shivam Gothi el 24 de Nov. de 2024
Thankyou for the reply. You can find the "preferences" tab as shown in the below figure.
Set the "Locale" property to "fr-FR" by manually typing it and then clicking "apply". It will only change the Locale of "datetime" object. Not the entire Command window.
I tried this and found to be working.
Moreover, if you find any of the responses helpful and they resolve the issue you're facing, it would be wonderful if you could mark the answer as "accepted". This will assist the community users in finding more precise and accurate solutions.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Graphics Object Programming en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by