This is a followup question to this question. Since it addresses a more general issue I make it a new question.
I have a network for which the labels of the nodes are in Farsi language (Arabic alphabet). When I try to use networkx
to display my network it shows blank squares instead of Arabic letters. Below I copy a good example provided in the answers in here.
from bidi.algorithm import get_display
import matplotlib.pyplot as plt
import arabic_reshaper
import networkx as nx
# Arabic text preprocessing
reshaped_text = arabic_reshaper.reshape(u'زبان فارسی')
artext = get_display(reshaped_text)
# constructing the sample graph
G=nx.Graph()
G.add_edge('a', artext ,weight=0.6)
pos=nx.spring_layout(G)
nx.draw_networkx_nodes(G,pos,node_size=700)
nx.draw_networkx_edges(G,pos,edgelist=G.edges(data=True),width=6)
# Drawing Arabic text
# Just Make sure your version of the font 'Times New Roman' has Arabic in it.
# You can use any Arabic font here.
nx.draw_networkx_labels(G,pos,font_size=20, font_family='Times New Roman')
# showing the graph
plt.axis('off')
plt.show()
which generates the following image:
I tried to install the needed fonts by following command lines in python, but I get the same thing.
>>> import matplotlib.pyplot
>>> matplotlib.rcParams.update({font.family' : 'TraditionalArabic'})
Here is the ERROR message, to be more specific:
/usr/local/anaconda3/lib/python3.5/site-packages/matplotlib/font_manager.py:1288: UserWarning: findfont: Font family ['TraditionalArabic'] not found. Falling back to Bitstream Vera Sans
(prop.get_family(), self.defaultFamily[fontext])
I am also investigating ways to install the needed fonts from ubuntu cli, if possible, and put it in my docker file as it gets installed every time I spin my runs.
Best regards, s.