I need to include arrows in a data table. I have achieved it successfully with some simple arrow characters (e.g. unicode '\u2191' for an up arrow). But the fonts that I have access to are limiting me from using some of the more detailed / interesting arrows.
This has led to me trying to use wingdings, which is installed on my system. In MS Word I can type 'kmg' - changing this text font to 'wingdings 3' makes them appear as arrows.
My attempt in the code below results in errors such as:
67: UserWarning: Glyph 112 (p) missing from font(s) Wingdings 3
861: UserWarning: Glyph 109 (m) missing from font(s) Wingdings 3
And the bottom row in the table us filled with only error boxes. Please can anyone guide me?
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
df = pd.DataFrame({"Before":[1,4,7,5,8,2,5,7], "After":[2,7,9,1,9,2,7,3]})
df["Change"]=df["After"]-df["Before"]
#Define arrow symbols
up_arrow = 'k' # Up arrow
down_arrow = 'm' # Down arrow
right_arrow = 'g' # Right arrow
#Create the arrchg row based on Change values
arrchg_row = []
for change in df["Change"]:
if change > 0:
arrchg_row.append(up_arrow)
elif change < 0:
arrchg_row.append(down_arrow)
else:
arrchg_row.append(right_arrow)
#Prepare the cell text for the table
cell_text = [df["Before"].values, df["After"].values, df["Change"].values, arrchg_row]
#Create the plot
fig, ax = plt.subplots()
#Hide axes
fig.patch.set_visible(False)
ax.axis('off')
ax.axis('tight')
#Create the table
rect=ax.table(
cellText=cell_text,
rowLabels=["Bef", "Arf", "chg", "arrchg"],
loc='lower center', # May need adjusting to 'lower center' or 'upper center' in Power BI
cellLoc='center'
)
#Set font properties for the first three rows
for (i, j), cell in rect.get_celld().items():
if i < 3: # First three rows
cell.set_fontsize(12)
cell.set_text_props(fontname='Arial') # Change to your desired font
else: # Last row with Wingdings
cell.set_fontsize(12)
cell.set_text_props(fontname='Wingdings 3')
fig.tight_layout()
plt.show()
I need to include arrows in a data table. I have achieved it successfully with some simple arrow characters (e.g. unicode '\u2191' for an up arrow). But the fonts that I have access to are limiting me from using some of the more detailed / interesting arrows.
This has led to me trying to use wingdings, which is installed on my system. In MS Word I can type 'kmg' - changing this text font to 'wingdings 3' makes them appear as arrows.
My attempt in the code below results in errors such as:
67: UserWarning: Glyph 112 (p) missing from font(s) Wingdings 3
861: UserWarning: Glyph 109 (m) missing from font(s) Wingdings 3
And the bottom row in the table us filled with only error boxes. Please can anyone guide me?
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
df = pd.DataFrame({"Before":[1,4,7,5,8,2,5,7], "After":[2,7,9,1,9,2,7,3]})
df["Change"]=df["After"]-df["Before"]
#Define arrow symbols
up_arrow = 'k' # Up arrow
down_arrow = 'm' # Down arrow
right_arrow = 'g' # Right arrow
#Create the arrchg row based on Change values
arrchg_row = []
for change in df["Change"]:
if change > 0:
arrchg_row.append(up_arrow)
elif change < 0:
arrchg_row.append(down_arrow)
else:
arrchg_row.append(right_arrow)
#Prepare the cell text for the table
cell_text = [df["Before"].values, df["After"].values, df["Change"].values, arrchg_row]
#Create the plot
fig, ax = plt.subplots()
#Hide axes
fig.patch.set_visible(False)
ax.axis('off')
ax.axis('tight')
#Create the table
rect=ax.table(
cellText=cell_text,
rowLabels=["Bef", "Arf", "chg", "arrchg"],
loc='lower center', # May need adjusting to 'lower center' or 'upper center' in Power BI
cellLoc='center'
)
#Set font properties for the first three rows
for (i, j), cell in rect.get_celld().items():
if i < 3: # First three rows
cell.set_fontsize(12)
cell.set_text_props(fontname='Arial') # Change to your desired font
else: # Last row with Wingdings
cell.set_fontsize(12)
cell.set_text_props(fontname='Wingdings 3')
fig.tight_layout()
plt.show()
Share
asked Mar 14 at 14:01
BaldyBaldy
575 bronze badges
2
|
1 Answer
Reset to default 0Try unicode:
up_arrow = '\u2197' # Up arrow
down_arrow = '\u2198' # Down arrow
right_arrow = '\u2192' # Right arrow
Comment out (or delete) the following:
#Set font properties for the first three rows
#for (i, j), cell in rect.get_celld().items():
# if i < 3: # First three rows
# cell.set_fontsize(12)
# cell.set_text_props(fontname='Arial') # Change to your desired fon t
# else: # Last row with Wingdings
# cell.set_fontsize(12)
# cell.set_text_props(fontname='Wingdings 3')
The output:
\u2197
instead ofk
,\u2198
instead ofm
and\u2192
instead ofg
. – Man made of meat Commented Mar 14 at 16:13