Skip to content

Commit

Permalink
Generates SVG from Plotly
Browse files Browse the repository at this point in the history
  • Loading branch information
saeedamen committed Apr 2, 2020
1 parent 5bce1f4 commit 58532ce
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,19 +128,21 @@ relatively small changes to your code base.
# Contributors

Contributors are always welcome for finmarketpy, findatapy and chartpy. If you'd like to contribute, have a look at
[Planned Features](https://github.com/cuemacro/finmarketpy/blob/master/PLANNED_FEATURES.md) for areas we're looking for help on. Or if you have any ideas for improvements
to the libriares please let us know too!
[Planned Features](https://github.com/cuemacro/finmarketpy/blob/master/PLANNED_FEATURES.md) for areas we're looking for help on.
Or if you have any ideas for improvements to the libriares please let us know too!

# chartpy examples

In chartpy/examples you will find several demos

# Release Notes
# Recent Release Notes

* No formal releases yet
* 02 Apr 2020 - v0.1.5
* 23 Oct 2019 - v0.1.4

# Coding log

* 02 Apr 2020 - Plotly can now produce SVG
* 02 Nov 2019 - Now supports Plotly 4.x with Cufflinks 0.17)
* 23 Oct 2019 - Added advisory on Plotly 3.10 and Cufflinks 0.16
* 19 Aug 2019 - Removed .ix usage, which is now deprecated in Pandas
Expand Down
11 changes: 10 additions & 1 deletion chartpy/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -1804,10 +1804,13 @@ def publish_plot(self, fig, style):
return plotly.io.to_image(fig, format='png') # PNG as bytes

elif style.plotly_plot_mode == 'offline_image_png_in_html':
# TODO also add Python 3 support for this
return '<img src="data:image/png;base64,' + \
base64.b64encode(plotly.io.to_image(fig, format='png')).decode(
'utf8') + '">' # PNG as bytes in HTML image
elif style.plotly_plot_mode == 'offline_image_svg_in_html':
return '<img src="data:image/svg;base64,' + \
base64.b64encode(plotly.io.to_image(fig, format='svg')).decode(
'utf8') + '">' # SVG as bytes in HTML image

# can display in HTML as <img src="data:image/png;base64,[ENCODED STRING GOES HERE]">

Expand All @@ -1817,6 +1820,12 @@ def publish_plot(self, fig, style):
py_offline.init_notebook_mode()
py_offline.iplot(fig)

elif style.plotly_plot_mode == 'offline_jupyter_connected':

# plot in IPython notebook
py_offline.init_notebook_mode(connected=True)
py_offline.iplot(fig)

# plotly.offline.plot(fig, filename=style.file_output, format='png',
# width=style.width * style.scale_factor, height=style.height * style.scale_factor)
elif style.plotly_plot_mode != 'dash':
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
also works well with Dash, plotly's web server library built on top of Flask."""

setup(name='chartpy',
version='0.1.4',
version='0.1.5',
description='chartpy creates a simple easy to use API to plot in a number of great Python chart libraries',
author='Saeed Amen',
author_email='[email protected]',
Expand Down

0 comments on commit 58532ce

Please sign in to comment.