Black Lives Matter. Please consider donating to Black Girls Code today.

Save as .svg instead of .png in modeBar

Hi, I was wondering if there was a way to change the modeBarButtons.toImage icon to save as a .svg instead of .png?

I made a temporary fix by downloading and editing the plotly.js directly, but I would really prefer another method.

This is the code I modified:

modeBarButtons.toImage = {
name: ‘toImage’,
title: ‘Download plot as a svg’,
click: function(gd) {
var format = ‘svg’;

    Lib.notifier('Taking snapshot - this may take a few seconds', 'long');

    if(Lib.isIE()) {
        Lib.notifier('IE only supports svg.  Changing format to svg.', 'long');
        format = 'svg';

    downloadImage(gd, {'format': format})
      .then(function(filename) {
          Lib.notifier('Snapshot succeeded - ' + filename, 'long');
      .catch(function() {
          Lib.notifier('Sorry there was a problem downloading your snapshot!', 'long');


Here’s one solution:

1 Like

Thank you! It worked! This is a much better.