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

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. 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
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.