9

Former R user, I used to combine extensively ggplot and plot_ly libraries via the ggplotly() function to display data.

Newly arrived in Python, I see that the ggplot library is available, but cant find anything on a simple combination with plotly for graphical reactive displays.

What I would look for is something like :

from ggplot import*
import numpy as np
import pandas as pd

a = pd.DataFrame({'grid': np.arange(-4, 4),
                 'test_data': np.random.random_integers(0, 10,8)})
p2 = ggplot(a, aes(x = 'grid', y = 'test_data'))+geom_line()
p2
ggplotly(p2)

Where the last line would launch a classic plotly dynamic viewer with all the great functionalities of mouse graphical interactions, curves selections and so on...

Thanks for your help :),

Guillaume

1
  • You can create graphs which are stored as HTML files or use a Jupyter Notebook to get interactive graphs together with your code. Commented May 29, 2018 at 15:55

2 Answers 2

4

This open plotnine issue describes a similar enhancement request.

Currently the mpl_to_plotly function seems to work sometimes (for some geoms?), but not consistently. The following code, seems to work ok.

from plotnine import *
from plotly.tools import mpl_to_plotly as ggplotly
import numpy as np
import pandas as pd

a = pd.DataFrame({'grid': np.arange(-4, 4),
             'test_data': np.random.randint(0, 10,8)})
p2 = ggplot(a, aes(x = 'grid', y = 'test_data')) + geom_point()
ggplotly(p2.draw())
Sign up to request clarification or add additional context in comments.

Comments

0

You don't need ggplotly in python if all you are seeking is an interactive interface. ggplot (or at least plotnine, which is the implementation that I am using) uses matplotlib which is already interactive, unlike the R ggplot2 package that requires plotly on top.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.