Hello,
I am currently testing with custom template files:
My goal is to be able to distribute this template to help with keeping a standardized design.
I placed my template.json in PythonXXX\Lib\site-packages\plotly\package_data\templates
and I have altered PythonXXX\Lib\site-packages\plotly\io\_templates.py by adding my template name in the default_templates list in the init method.
To make it the default template, I changed PythonXXX\Lib\site-packages\plotly\io\_init_.py’s last row to templates._default = “template_name”
I’m very happy with this result. After making these changes, every new plot I create automatically uses my custom layout (If import plotly in dark-themed PyCharm would not automatically overwrite the template to ‘plotly_dark’ but thats a different story; currently I am not able to find a solution because I am not very familiar with PyCharm,Jupyter,IPython… technical details)
Currently I am also trying to figure out how to auto-place images on these plots.
{
“layout”: {
“images”:[
{
“sizex”: 0.15,
“sizey”: 0.15,
“source”: “http://upload.wikimedia.org/wikipedia/commons/4/44/Kaufland_201x_logo.svg”,
“x”: 1.22,
“xanchor”: “right”,
“xref”: “paper”,
“y”: -0.2,
“yanchor”: “bottom”,
“yref”: “paper”,
“name”:“KauflandLogo”,
“layer”:“above”
}
placing this in my template.json causes this entry when importing plotly:
I’ve hit a slight roadblock with the images, however. I’ve noticed that the logo is not appearing on the plot. When I inspect fig.layout
, there is no images entry, even though the image object is correctly defined within the template under fig.layout.template.layout.images
.
It seems the images from the template aren’t being applied to the final plot layout.
Manually adding a image via fig.add_layout_image
causes this entry:
Comparing my template.layout.images to my fig.layout.images entry, I am unable to find any difference.
I would be very grateful if someone could explain why every detail of my template—except for the image—is being transferred into the new figure. I’m wondering if this has something to do with a validation step in the plot-creation process, and I am happy to alter the code for a successful solution.