I am using plot.ly to plot some graphs on some data. The graph is shown correctly but I would like to get a url to the graph that is hosted on plot.ly/username/xxx. Is there a way to get the url programmatically? I checked the plot.ly documentation but did not come across this option.
By default when creating plot. The URL are passed by the function
import plotly.plotly as py
url = py.plot(fig, filename='stacked-bar')
Related
Can you make mpld3-matplotlib interactive ?
what I mean is display a graph on a web page and be able to update the time series i.e. not simply static graph, but dynamic one page graph-app ?
What can be leveraged from mpld3 ?
if you don't have to support matplotlib then an option is Bokeh or Dash library instead.
I've been using bokeh to plot data on a map using bokeh.
Is there a way to work with this library outside jupyter notebook?
Something like in Pychram and saving the plot to HTML file.
Bokeh can generate complete HTML pages for Bokeh documents using the file_html() function. you can refer Embedding Plots and Apps for more detail.
from bokeh.plotting import figure
from bokeh.resources import CDN
from bokeh.embed import file_html
plot = figure()
plot.circle([1,2], [3,4])
html = file_html(plot, CDN, "my plot")
So, I'm learning how to use matplotlib and stumbled into MPLD3 as the most used way to get these plots in a webpage. However, MPLD3 doesn't support tick formatting and that's something critical for the project I'm in right now. I'd like to know if there is another way to add a matplotlib graph to a webpage while keeping the tick formatting and also having tooltips to display data on hover.
Thanks!
For a web application I would consider bokeh. You can output html with interactive charts or run another backend server. If you go to the ipython notebook tutorial section 10 has demos for embedding.
Alternatively you can just save images from matplotlib and use them as static assets in your page.
I am trying to build webpage showing an interactive map (taking up 100% of the page) where I present points or lines with information. Plotly seems perfect for this and I really like its visualization but it does however not have support for maps such as Open Street Map built in, it uses Mapbox for this. I don't have anything against Mapbox, but from what I can find it is free of charge up to a certain numbers of views (while it uses OSM).
Simply said: is there an easy (as open source and free to use) way using python to build such a webpage with a map that shows information?
There is indeed! You can use Mapbox GL JS without plotly. There are example of html code in here that will create these full sized maps for you. They can be satellite or just a plain map.
Drawing lines:
https://docs.mapbox.com/mapbox-gl-js/example/geojson-line/
Creating a popup onclick:
https://docs.mapbox.com/mapbox-gl-js/example/popup-on-click/
You can indeed use OSM maps free of charge without restrictions or a Mapbox API account in Plotly and Dash, see https://plotly.com/python/mapbox-layers/:
Base Maps in layout.mapbox.style
The accepted values for layout.mapbox.style are one of:
"white-bg" yields an empty white canvas which results in no external HTTP requests
"open-street-map", "carto-positron", "carto-darkmatter", "stamen-terrain", "stamen-toner" or "stamen-watercolor" yeild maps composed of raster tiles from various public tile servers which do not require signups or access tokens
"basic", "streets", "outdoors", "light", "dark", "satellite", or "satellite- streets" yeild maps composed of vector tiles from the Mapbox service, and do require a Mapbox Access Token or an on-premise Mapbox installation.
A Mapbox service style URL, which requires a Mapbox Access Token or an on-premise Mapbox installation.
A Mapbox Style object as defined at https://docs.mapbox.com/mapbox-gl-js/style-spec/
Here is a code example from the same plotly documentation that uses the OSM basemap without any authetification token:
import pandas as pd
us_cities = pd.read_csv("https://raw.githubusercontent.com/plotly/datasets/master/us-cities-top-1k.csv")
import plotly.express as px
fig = px.scatter_mapbox(us_cities, lat="lat", lon="lon", hover_name="City", hover_data=["State", "Population"],
color_discrete_sequence=["fuchsia"], zoom=3, height=300)
fig.update_layout(mapbox_style="open-street-map")
fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0})
fig.show()
As for builing an actual website, I recommend using Dash, which is a webserver well integrated with plotly.
I have created a plot in R using rbokeh and I want to convert it to HTML/Javascript in order to embed it inside a web page. I'm currently able to achieve this with mpld3 on Python (and I know that bokeh on python does it too) but I want to be able to do this with rbokeh in R. So basically I'm looking for something similar to Python's mpld3.fig_to_html(), e.g:
fig, ax = plt.subplots()
ax.p1 = plt.bar(...)
html = mpld3.fig_to_html(fig) # <- converts the plot to html/javascript!
print html # prints out the html/javascript code as text
Or using Python's bokeh module: embed.autoload_static()
Can rbokeh plots be converted to html/JavaScript code?
Many thanks in advance.
It appears that, to date, saveWidget is the closest to what I want, so thanks hrbrmstr. I wanted to avoid having to read and write from the disk every time a graph is exported to html but it's not possible yet.