Following the plotly tutorial on getting static images through the python api.
When I execute:
import plotly as py
py.offline.plot(data,
show_link=False,
image_filename='pandas-bar-chart-binned',
image='png')
My browser auto opens and I get both an HTML file in my parent directory and an image of the chart downloads from the browser, which is to be expected from the docs.
But if I execute:
import plotly as py
py.offline.plot(data,
show_link=False,
image_filename='pandas-bar-chart-binned',
image='png',
auto_open=False)
The HTML file is generated in my parent directory, but no image is produced. If I store it as a variable, I get a string that represents the location of the HTML file.
Is there a save_as function for offline, as there is for image?
import plotly as py
py.plotly.image.save_as(data, filename='pandas-bar-chart-binned.png')
I have found a handful of suggestions, but they all seem to point back to opening up a browser rather than saving directly through the file system.
Related
how can I display (and scale) two local html files in the Jupyter Notebook side-by-side?
I failed to transfer a solution for images to html files...
from IPython.display import IFrame
from IPython.core.display import display, HTML
# display single local image >>>>>>>>>>>>>>>>>>>>>>>>>>>
IFrame(src='figure1.html', width=1660, height=800)
This does not work:
display(HTML("<table><tr><td><img src='fig1.html'></td><td><img src='fig2.html'></td></tr></table>"))
Is it possible to load this figure into the first column of an html
table and add another to the second column?
The ultimate idea is to export the notebook as slides and have two interactive plots on the slides.
I want to display a markdown(readme) file into an odoo view as a field, i'm using the parser mistune to parse the file into an html format; as a result, the text is displayed as expected, except for every images located in src/img folder for the odoo module structure.
(example of image: ![Capture](static/src/img/usecase.png))
I've tried with the html inspector and it says the image wasn't found, and when I hover it, the path is http://server-s551lb:8069/static/src/img/usecase.png and I find it weird because it's only the relative path to locate the image.
Any help or idea would be welcome:)
I've found by adding modulename/ before static from the relative path of the image :)
I am using Google Colab to work create maps with Python 3.0 and I have done so using Basemaps. I am next trying to create similar maps using Google Maps. There are two python packages that I have located namely gmaps and gmplot. It seems as if gmaps requires a google API but gmplot does not hence I am using gmplot.
With gmplot, I am able to create a file 'my_map.html' which if I download to my local desktop, I can open in a browser and see the map correctly.
However I would like to see the map in the notebook output cell without downloading to the local machine. The following image is a screenshot of what I have tried ... there is no error, but no display either.
is there some command like %matplotlib inline that i need execute to be able to display the contents of the file in the output cell? or is there a better solution
Try full path to your file: /content/my_map.html
The code should be:
import IPython
IPython.display.HTML(filename='/path/to/your/filename')
Please Try Following code:
from IPython.display import IFrame
IFrame(src='path/to/your/filename.html', width=900, height=600)
It did work for me. :)
This solution is not working for me if the html contains images located on colab or in your (mapped) google-drive:
IPython.display.HTML('<img src="/content/elmo_1.jpg">') # can't find image
IPython.display.HTML('<img src="/content/gdrive/My Drive/elmo_1.jpg">') # can't find image
IPython.display.HTML('<img src="/content/gdrive/My%20Drive/elmo_1.jpg">') # can't find image
It works, however, with standard url:
IPython.display.HTML('<img src="https://github.com/blablabla/elmo_1.jpg?raw=1">')
Colab won't display local file images in html. You need to convert a png file to base64
encoded = base64.b64encode(open(png_file_name, "rb").read())
And show image using
<img src=f"data:image/png;base64,{encoded.decode('utf-8')}" alt="" width="600" height="400">
I'm using motionless in python (3.5) to build static map images.
I was having a hard time to create custom markers. But it seems like it's not so much the framework or my code, but the google maps API itself.
I can't figure out what's wrong with my URL,while this URL, works.
I use this icon:
https://raw.githubusercontent.com/havnar/sprites/master/ico/1.ico
While the stack overflow favicon just works:
http://cdn.sstatic.net/Sites/stackoverflow/img/favicon.ico
There was an issue with your icon file. I have re-saved the file out and uploaded to my own Github and it loads fine now:
https://maps.googleapis.com/maps/api/staticmap?zoom=17&size=512x512&maptype=hybrid&markers=icon:https://raw.githubusercontent.com/zensign/ico-test/master/favicon3.ico%7C34.052230%2C-118.243680
You can grab the working .ico file here: https://raw.githubusercontent.com/zensign/ico-test/master/favicon3.ico
I generate a plotly graph using this:
import plotly.plotly as py
import plotly.graph_objs as go
fig = go.Figure(data=data, layout=layout)
plot_url = py.plot(fig, filename='stacked-bar')
I tried generating a pdf using:
from xhtml2pdf import pisa
result_file = open('report.pdf', "w+b")
pisa_status = pisa.CreatePDF(
url,
dest=result_file)
result_file.close()
But I end up getting a pdf file with the url on it instead of the graph.
How can I export the plotly graph into a pdf? One the webpage, when I click the export button I am able to generate a jpeg and png but not a pdf. Also, I'm unable to control the size of the graph when exporting the, how can I control the size? Stretch out the graph making it a little wider.
Thanks.
The APIs have now changed, so I thought I'd post an update..
The new way of doing it is to use plotly.io.write_image
Here is an example:
plotly.io.write_image(fig, 'output_file.pdf', format='pdf')
The following formats are supported: png, jpg (or jpeg), webp, svg, pdf
According to documentation for offline usage https://plot.ly/python/offline/ you can export images with:
plotly.plotly.image.save_as(figure, 'my_plot.png')
But to export pdf you have to have a paid account. Using free account you can export only png or jpg formats (100 API calls a day). But not pdfs.
In case if you stack with the error like:
exceptions.PlotlyError(return_data['error'])
than there is a chance that you have some authentication problems to access Plotly API. Make sure you have an account and configure you ~/.plotly/.credentials with correct user name and api_key (you can find it in profile settings).
To control the size of the graph you need to setup your layout accordingly.