python - Writing Greek in matplotlib labels, titles -


I'm trying to write some text for labels, shape titles etc. with my plots, but no benefit till now Has not happened .

I do not want to print specific characters (I know how to use special characters), I want to write the entire text in Greek (maybe Unicode and text '?).

, suggesting that I would like to mention that for some reason I can not get matplotlib to cooperate with Tex (using IPython notebook from Anaconda in Ubuntu 14.10) so that there really is an option Will not be the first.

I tried loading the Arial font and it loads successfully but again I get square blocks instead of characters. I

  import matplotlib.font_manager FM PROP = FM Font Properties (fname = '/ usr / share / fonts / truetype / msttcorefonts / Arial.ttf')   

And then to display the string I u'Î? ? I ?? Î¿Ï ?? ÎμÎ »second ?? μΠ± i ?? I ± i ?? I ?? Used ο किया? ? Î¿Î¼Î¿Î¯Ï ?? I ?? I · I ?? '. Ariel is considered to be fully presented to Greek and I have used it many times in text editors.

I managed to resolve the problem by doing the following:

First of all, you To make sure that the necessary libraries are imported and installed on a computer, Greek render (font like Ubuntu Ubuntu font, set to bold in the following code).

  import matplotlib.font_manager to FM fp1 = fm.FontProperties (fname = '/ usr / share / fonts / truetype / ubuntu-font-family / Ubuntu-bttf')   

Then you can apply the selected label to each label, title etc. as follows:

  plt.title (u "Î¤Î¯Ï ?? Î »Î¿Ï ?? I ?? Î¿Ï ?? Î³Ï ?? I ± I ?? ήμΠ± I ?? Î¿Ï ??", fontproperties = FP1)   

If that does not work, try adding the following line at the beginning of the file:

  # - * - coding: utf-8 - * -   

A sample plot is provided to prove the purity of: as the import matplotlib.pyplot import plat import matplotlib.font_manager as FM import numpy as np fp1 = fm. FontProperties (fname = '/ usr / share / fonts / truetype / ubuntu-font-family / Ubuntu-bttf') data = np.random.randn (5000) # generate some random data plt.plot (data) plt.title ( U "Î¤Î¯Ï ?? Î »Î¿Ï ?? I ?? Î¿Ï ?? Î³Ï ?? Î ± Ï ?? ήΠ± ± Ï ?? Î¿Ï ?? ", Fontproperties = fp1) plt.xlabel (U" Î ?? ξο½½Î ± Ï ?? x ", fontproperties = fp1) plt .ylabel (U" i ?? ¾¾km ½ i? Y ", fontproperties = FP1) plt.show ()

You should give something like this:

 example graph

Comments

Popular posts from this blog

c# - LINQ to Entities does not recognize the method 'Int32 IndexOf(System.String, System.StringComparison)' method -

Pygame memory leak with transform.flip -