Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
jtspilker
Helper I
Helper I

Changing font in Python visual

Does anyone know if it's possible to render a Python visual in a non-default font (default=Deja Vu Sans) in Service? I'm trying to create a Python visual using the DIN font to match the rest of my report, but in the Service, that visual just renders using the default font. I thought maybe it was because DIN isn't pre-loaded so tried using a rough equivalent of Bahnschrift, but that didn't work either. Thoughts?

4 REPLIES 4
amitamola
Microsoft Employee
Microsoft Employee

After lot of struggle I was able to make it work.
So the original was this:

 
 

undefined.png


And the new font one is:
undefined (1).png
This is how I did it:

 

  1. I first uploaded the font I wanted in ADLS gen 2 storage I had. I usually used it to load the data from datalake, so I thought this should work as well.
  2. Next step was to get the link for that file I just uploaded. It's simple enough,  right click on the file, properties and there's the URL.
  3. In your Synapse notebook, import your usual commands first:
    import numpy as np
    import pandas as pd
    import matplotlib.pyplot as plt
    %matplotlib inline

    And then what we will do is use the mssparkutils, this is Synapse provided built-in way to access storage accounts. So we run this:

    mssparkutils.fs.cp(<the link copied above>, 'file:///tmp/<your font name.ttf or .otf>')

    In my case it was Barlow font, so we check if downloaded as below:

    print("Font file 'Barlow-Regular.ttf' downloaded successfully.")

    # Verify the file was downloaded
    import os
    if os.path.exists('/tmp/Barlow-Regular.ttf'):
        print("File exists in the /tmp directory.")
        print(f"File size: {os.path.getsize('/tmp/Barlow-Regular.ttf')} bytes")
    else:
        print("File does not exist in the /tmp directory.")

    And now just register it in Matplotlib as below:

    from matplotlib import font_manager

    font_path = "/tmp/Barlow-Regular.ttf"
    font_manager.fontManager.addfont(font_path)
    prop = font_manager.FontProperties(fname=font_path)

    plt.rcParams['font.family'] = 'sans-serif'
    plt.rcParams['font.sans-serif'] = prop.get_name()
     
  4. And now plot anything you want and it will make the plot with this font.
     
    NOTE - You do need to do the mssparkutils part for downloading again perhaps for each session, but that's easy enough to do.
     
lbendlin
Super User
Super User

You may want to provide more details.  Which renderer are you using? Pyplot ?

 

How to Change Fonts in Matplotlib (With Examples) - Statology

Sorry - yes, matplotlib pyplot.

 

The link you provided shows how to change font in the python code itself. I don't have any issues with that. I can change the font and it updates fine in Power BI Desktop. When I publish the report to Service, though, all those font changes to DIN don't hold and the python visual defaults back to matplotlib's default font of Deja Vu Sans.

That's too bad. Maybe you can ask the product team what they support in that area. I am only aware of an article about supported python packages.  https://docs.microsoft.com/en-us/power-bi/connect-data/service-python-packages-support

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.