Black Lives Matter. Please consider donating to Black Girls Code today.
Dash HoloViews is now available! ✅Check out the new docs.

Is image=foo required for image_filename=bar with plotly.offline.plot?

Here’s my example:

import pandas as pd
import plotly
import plotly.graph_objs as go

df = pd.DataFrame(
    {'fruits': ['Apples', 'Pears', 'Nectarines', 'Plums', 'Grapes', 'Strawberries'],
     'counts': [5, 3, 4, 2, 4, 6] })

data = [go.Bar(x=df['fruits'],

fname = 'fruit-plot'

plotly.offline.plot(data, filename='{}.html'.format(fname), auto_open=False,
                    image_filename=fname, image='png')

This gives me a html file (without auto-opening it). When I do open it, the file fruit-plot.png is automatically downloaded to ~/Downloads (using chromium). I attempted not to specify image='png' as I don’t want to auto-download the file, but I do want to specify it’s name.

plotly.offline.plot(data, filename='{}.html'.format(fname), auto_open=False,

Now when I click the camera, I get the file newplot.png.

The docs don’t really explain how one might change the default filename while avoiding the auto-download behavior. These are the only relevant options I see:

image (default=None |'png' |'jpeg' |'svg' |'webp') -- This parameter sets
        the format of the image to be downloaded, if we choose to download an
        image. This parameter has a default value of None indicating that no
        image should be downloaded. Please note: for higher resolution images
        and more export options, consider making requests to our image servers.
        Type: `help(py.image)` for more details.
 image_filename (default='plot_image') -- Sets the name of the file your
        image will be saved to. The extension should not be included.

If these two need to be used in conjunction (image_filename sort of “requires” image='type'), could the docs be updated to this effect?

I was able to answer this in my looking through ./plotly/offline/

            if image:
                if image not in __IMAGE_FORMATS:
                    raise ValueError('The image parameter must be one of the '
                                     'following: {}'.format(__IMAGE_FORMATS)
                # if the check passes then download script is injected.
                # write the download script:
                script = get_image_download_script('plot')
                script = script.format(format=image,
                script = ''

In other words, if you specify image='type', it embeds the script that downloads the file as image_filename; otherwise the script is empty and you get the global plotly name of newplot. I filed an issue as I would like an option to somehow provide a filename associated with that camera button, but don’t want the .html to download files every time I open it.