First, check the version which version of the Python API installed on your machine:
import plotly
plotly.__version__
'1.1.0'
Import the Plotly modules:
import plotly.plotly as py # to comminucate with plotly, sign in done with credentials
import plotly.tools as tls # some plotly tools
Use get_figure()
to pull down the figure object into an Python/IPython session:
figure = py.get_figure('al_indigo', '38')
# Or
#figure = py.get_figure('https://plot.ly/~al_indigo/38/4-1-2-trinity/')
# or
#figure = py.get_figure('https://plot.ly/~al_indigo/38')
print figure.to_string() # show graph objects contained in figure
Figure( data=Data([ Bar( x=['AAAA', 'AAAC', 'AAAG', 'AAAN', 'AAAT', 'AACA', 'AACC', 'AAC...], y=[0.005415793151642208, 0.004251106452364314, 0.00652224551595...], name=u'4-\u0433\u0440\u0430\u043c\u043c\u044b \u0440\u0438\u043...', marker=Marker( color='black' ), opacity=0.9 ), Bar( x=['AAAA', 'AAAC', 'AAAG', 'AAAN', 'AAAT', 'AACA', 'AACC', 'AAC...], y=[0.0052323470868173225, 0.004580653979317374, 0.0060799796530...], name=u'4-\u0433\u0440\u0430\u043c\u043c\u044b \u0440\u0438\u043...', marker=Marker( color='grey' ), opacity=0.9 ) ]), layout=Layout( title=u'\u0412\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u044...', xaxis={'autotick': False, 'dtick': 25, 'title': u'4-\u0433\u0440\u0...}, yaxis={'title': u'\u0412\u0435\u0440\u043e\u044f\u0442\u043d\u043e\...}, legend=Legend( x=0, y=1 ) ) )
To modify the size of the figure, update the figure object with the following key-value pairs:
figure['layout'].update(
autosize=False, # N.B. set custom size!
width=1400, # figure's width in pixels
height=1000 # figure's height in pixels
)
Now call image.save_as()
sending the updated figure object:
help(py.image)
Help on class image in module plotly.plotly.plotly: class image | Helper functions wrapped around plotly's static image generation api. | | Class methods defined here: | | ishow(cls, figure_or_data, format='png', width=None, height=None) from __builtin__.classobj | Display a static image of the plot described by `figure` | in an IPython Notebook. | | save_as(cls, figure_or_data, filename, format=None, width=None, height=None) from __builtin__.classobj | Save a static image of the plot described by `figure` locally as `filename`. | Valid image formats are 'png', 'svg', 'jpeg', and 'pdf'. | The format is taken as the extension of the filename or as the supplied format. | | ---------------------------------------------------------------------- | Static methods defined here: | | get(figure_or_data, format='png', width=None, height=None) | Return a static image of the plot described by `figure`. | | Valid formats: 'png', 'svg', 'jpeg', 'pdf'
py.image.save_as(figure, 'test.png')
py.image.save_as(figure, 'test.svg')
py.image.save_as(figure, 'test.jpeg')
py.image.save_as(figure, 'test.pdf')
%%bash --out file_out
file test.{png,svg,jpeg,pdf}
print file_out
test.png: PNG image data, 1400 x 1000, 8-bit/color RGBA, non-interlaced test.svg: ASCII text, with very long lines, with no line terminators test.jpeg: JPEG image data, JFIF standard 1.01 test.pdf: PDF document, version 1.3
Refer to
About Plotly
Big thanks to
from IPython.display import display, HTML
import urllib2
url = 'https://raw.githubusercontent.com/plotly/python-user-guide/master/custom.css'
display(HTML(urllib2.urlopen(url).read()))