How to plot interactive draw-able image using matplotlib in Google Colab?How do you change the size of figures drawn with matplotlib?How to change the font size on a matplotlib plotHow to put the legend out of the plotWhen to use cla(), clf() or close() for clearing a plot in matplotlib?Save plot to image file instead of displaying it using MatplotlibHow to make IPython notebook matplotlib plot inlineJupyter notebook canvas not interactive when using %matplotlib inlineBest way to interactively draw a line on a 2D matplotlib plotScientific Notation in matplotlib inline plots in jupyterMatplotlib imshow show all pixels
Diet Coke or water?
Is it OK to bring delicacies from hometown as tokens of gratitude for an out-of-town interview?
Short story written from alien perspective with this line: "It's too bright to look at, so they don't"
How to split a string in two substrings of same length using bash?
What is a simple, physical situation where complex numbers emerge naturally?
What flavor of zksnark in tezos
I completed a difficult task using a tool I developed before joining my employer. What is my obligation?
Did thousands of women die every year due to illegal abortions before Roe v. Wade?
Why was it possible to cause an Apple //e to shut down with SHIFT and paddle button 2?
Is it legal in the UK for politicians to lie to the public for political gain?
What does it mean by "d-ism of Leibniz" and "dotage of Newton" in simple English?
Old black and white movie: glowing black rocks slowly turn you into stone upon touch
Why does a helium balloon rise?
You've spoiled/damaged the card
What are the words for people who cause trouble believing they know better?
What happens if you do emergency landing on a US base in middle of the ocean?
Count line of code for Javascript project
Metal bar on DMM PCB
What do we gain with higher order logics?
How can Iron Man's suit withstand this?
The term for the person/group a political party aligns themselves with to appear concerned about the general public
Do I include animal companions when calculating difficulty of an encounter?
Explain Ant-Man's "not it" scene from Avengers: Endgame
Accidentally cashed a check twice
How to plot interactive draw-able image using matplotlib in Google Colab?
How do you change the size of figures drawn with matplotlib?How to change the font size on a matplotlib plotHow to put the legend out of the plotWhen to use cla(), clf() or close() for clearing a plot in matplotlib?Save plot to image file instead of displaying it using MatplotlibHow to make IPython notebook matplotlib plot inlineJupyter notebook canvas not interactive when using %matplotlib inlineBest way to interactively draw a line on a 2D matplotlib plotScientific Notation in matplotlib inline plots in jupyterMatplotlib imshow show all pixels
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I'm trying to plot an interactive image which will let me draw lines in output of Google Colab Notebook. I tried using the below code. It's working fine in my local Jupyter Notebook but its not working in Google colab.
Can anyone suggest any workaround on this?
Also tried to add %matplotlib inline, but it showed the still image.
from matplotlib.lines import Line2D
%pylab notebook
%matplotlib inline
#This is needed for plot widgets
class Annotator(object):
def __init__(self, axes):
self.axes = axes
self.xdata = []
self.ydata = []
self.xy = []
self.drawon = False
def mouse_move(self, event):
if not event.inaxes:
return
x, y = event.xdata, event.ydata
if self.drawon:
self.xdata.append(x)
self.ydata.append(y)
self.xy.append((int(x),int(y)))
line = Line2D(self.xdata,self.ydata)
line.set_color('r')
self.axes.add_line(line)
plt.draw()
def mouse_release(self, event):
# Erase x and y data for new line
self.xdata = []
self.ydata = []
self.drawon = False
def mouse_press(self, event):
self.drawon = True
img = np.zeros((28,28,3),dtype='uint8')
fig, axes = plt.subplots(figsize=(3,3))
axes.imshow(img)
plt.axis("off")
plt.gray()
annotator = Annotator(axes)
plt.connect('motion_notify_event', annotator.mouse_move)
plt.connect('button_release_event', annotator.mouse_release)
plt.connect('button_press_event', annotator.mouse_press)
axes.plot()
plt.show()
I expect the output to be Interactive in Google Colab just like Jupyter notebook in my PC, but the output is still image and nothing can be drawn over it.
matplotlib mouse draw interactive google-colaboratory
add a comment |
I'm trying to plot an interactive image which will let me draw lines in output of Google Colab Notebook. I tried using the below code. It's working fine in my local Jupyter Notebook but its not working in Google colab.
Can anyone suggest any workaround on this?
Also tried to add %matplotlib inline, but it showed the still image.
from matplotlib.lines import Line2D
%pylab notebook
%matplotlib inline
#This is needed for plot widgets
class Annotator(object):
def __init__(self, axes):
self.axes = axes
self.xdata = []
self.ydata = []
self.xy = []
self.drawon = False
def mouse_move(self, event):
if not event.inaxes:
return
x, y = event.xdata, event.ydata
if self.drawon:
self.xdata.append(x)
self.ydata.append(y)
self.xy.append((int(x),int(y)))
line = Line2D(self.xdata,self.ydata)
line.set_color('r')
self.axes.add_line(line)
plt.draw()
def mouse_release(self, event):
# Erase x and y data for new line
self.xdata = []
self.ydata = []
self.drawon = False
def mouse_press(self, event):
self.drawon = True
img = np.zeros((28,28,3),dtype='uint8')
fig, axes = plt.subplots(figsize=(3,3))
axes.imshow(img)
plt.axis("off")
plt.gray()
annotator = Annotator(axes)
plt.connect('motion_notify_event', annotator.mouse_move)
plt.connect('button_release_event', annotator.mouse_release)
plt.connect('button_press_event', annotator.mouse_press)
axes.plot()
plt.show()
I expect the output to be Interactive in Google Colab just like Jupyter notebook in my PC, but the output is still image and nothing can be drawn over it.
matplotlib mouse draw interactive google-colaboratory
The docs contain several interactive examples for Altair and plotly. (Not sure what's required for matplotlib.)
– Bob Smith
Mar 24 at 17:08
I don't think Google Colab has support for any of the interactive backends (like %matplotlib notebook, or %matplotlib ipympl). Jupyter notebook or jupyterhub may be better suited for that case.
– ImportanceOfBeingErnest
Mar 24 at 22:55
Thanks, @BobSmith but I need the interactive output in Colab, which I guess is not possible.
– Alankrit Mishra
Mar 25 at 3:03
Hi @ImportanceOfBeingErnest, I want to leverage Colab GPU for taining my model. And If Jupyter notebook or jupyterhub can only provide interactive backends. Can you please suggest how I can connect the trained model of Colab with the Jupyter notebook in order to usematplotlib.
– Alankrit Mishra
Mar 25 at 3:08
add a comment |
I'm trying to plot an interactive image which will let me draw lines in output of Google Colab Notebook. I tried using the below code. It's working fine in my local Jupyter Notebook but its not working in Google colab.
Can anyone suggest any workaround on this?
Also tried to add %matplotlib inline, but it showed the still image.
from matplotlib.lines import Line2D
%pylab notebook
%matplotlib inline
#This is needed for plot widgets
class Annotator(object):
def __init__(self, axes):
self.axes = axes
self.xdata = []
self.ydata = []
self.xy = []
self.drawon = False
def mouse_move(self, event):
if not event.inaxes:
return
x, y = event.xdata, event.ydata
if self.drawon:
self.xdata.append(x)
self.ydata.append(y)
self.xy.append((int(x),int(y)))
line = Line2D(self.xdata,self.ydata)
line.set_color('r')
self.axes.add_line(line)
plt.draw()
def mouse_release(self, event):
# Erase x and y data for new line
self.xdata = []
self.ydata = []
self.drawon = False
def mouse_press(self, event):
self.drawon = True
img = np.zeros((28,28,3),dtype='uint8')
fig, axes = plt.subplots(figsize=(3,3))
axes.imshow(img)
plt.axis("off")
plt.gray()
annotator = Annotator(axes)
plt.connect('motion_notify_event', annotator.mouse_move)
plt.connect('button_release_event', annotator.mouse_release)
plt.connect('button_press_event', annotator.mouse_press)
axes.plot()
plt.show()
I expect the output to be Interactive in Google Colab just like Jupyter notebook in my PC, but the output is still image and nothing can be drawn over it.
matplotlib mouse draw interactive google-colaboratory
I'm trying to plot an interactive image which will let me draw lines in output of Google Colab Notebook. I tried using the below code. It's working fine in my local Jupyter Notebook but its not working in Google colab.
Can anyone suggest any workaround on this?
Also tried to add %matplotlib inline, but it showed the still image.
from matplotlib.lines import Line2D
%pylab notebook
%matplotlib inline
#This is needed for plot widgets
class Annotator(object):
def __init__(self, axes):
self.axes = axes
self.xdata = []
self.ydata = []
self.xy = []
self.drawon = False
def mouse_move(self, event):
if not event.inaxes:
return
x, y = event.xdata, event.ydata
if self.drawon:
self.xdata.append(x)
self.ydata.append(y)
self.xy.append((int(x),int(y)))
line = Line2D(self.xdata,self.ydata)
line.set_color('r')
self.axes.add_line(line)
plt.draw()
def mouse_release(self, event):
# Erase x and y data for new line
self.xdata = []
self.ydata = []
self.drawon = False
def mouse_press(self, event):
self.drawon = True
img = np.zeros((28,28,3),dtype='uint8')
fig, axes = plt.subplots(figsize=(3,3))
axes.imshow(img)
plt.axis("off")
plt.gray()
annotator = Annotator(axes)
plt.connect('motion_notify_event', annotator.mouse_move)
plt.connect('button_release_event', annotator.mouse_release)
plt.connect('button_press_event', annotator.mouse_press)
axes.plot()
plt.show()
I expect the output to be Interactive in Google Colab just like Jupyter notebook in my PC, but the output is still image and nothing can be drawn over it.
matplotlib mouse draw interactive google-colaboratory
matplotlib mouse draw interactive google-colaboratory
asked Mar 24 at 13:09
Alankrit MishraAlankrit Mishra
65
65
The docs contain several interactive examples for Altair and plotly. (Not sure what's required for matplotlib.)
– Bob Smith
Mar 24 at 17:08
I don't think Google Colab has support for any of the interactive backends (like %matplotlib notebook, or %matplotlib ipympl). Jupyter notebook or jupyterhub may be better suited for that case.
– ImportanceOfBeingErnest
Mar 24 at 22:55
Thanks, @BobSmith but I need the interactive output in Colab, which I guess is not possible.
– Alankrit Mishra
Mar 25 at 3:03
Hi @ImportanceOfBeingErnest, I want to leverage Colab GPU for taining my model. And If Jupyter notebook or jupyterhub can only provide interactive backends. Can you please suggest how I can connect the trained model of Colab with the Jupyter notebook in order to usematplotlib.
– Alankrit Mishra
Mar 25 at 3:08
add a comment |
The docs contain several interactive examples for Altair and plotly. (Not sure what's required for matplotlib.)
– Bob Smith
Mar 24 at 17:08
I don't think Google Colab has support for any of the interactive backends (like %matplotlib notebook, or %matplotlib ipympl). Jupyter notebook or jupyterhub may be better suited for that case.
– ImportanceOfBeingErnest
Mar 24 at 22:55
Thanks, @BobSmith but I need the interactive output in Colab, which I guess is not possible.
– Alankrit Mishra
Mar 25 at 3:03
Hi @ImportanceOfBeingErnest, I want to leverage Colab GPU for taining my model. And If Jupyter notebook or jupyterhub can only provide interactive backends. Can you please suggest how I can connect the trained model of Colab with the Jupyter notebook in order to usematplotlib.
– Alankrit Mishra
Mar 25 at 3:08
The docs contain several interactive examples for Altair and plotly. (Not sure what's required for matplotlib.)
– Bob Smith
Mar 24 at 17:08
The docs contain several interactive examples for Altair and plotly. (Not sure what's required for matplotlib.)
– Bob Smith
Mar 24 at 17:08
I don't think Google Colab has support for any of the interactive backends (like %matplotlib notebook, or %matplotlib ipympl). Jupyter notebook or jupyterhub may be better suited for that case.
– ImportanceOfBeingErnest
Mar 24 at 22:55
I don't think Google Colab has support for any of the interactive backends (like %matplotlib notebook, or %matplotlib ipympl). Jupyter notebook or jupyterhub may be better suited for that case.
– ImportanceOfBeingErnest
Mar 24 at 22:55
Thanks, @BobSmith but I need the interactive output in Colab, which I guess is not possible.
– Alankrit Mishra
Mar 25 at 3:03
Thanks, @BobSmith but I need the interactive output in Colab, which I guess is not possible.
– Alankrit Mishra
Mar 25 at 3:03
Hi @ImportanceOfBeingErnest, I want to leverage Colab GPU for taining my model. And If Jupyter notebook or jupyterhub can only provide interactive backends. Can you please suggest how I can connect the trained model of Colab with the Jupyter notebook in order to use
matplotlib.– Alankrit Mishra
Mar 25 at 3:08
Hi @ImportanceOfBeingErnest, I want to leverage Colab GPU for taining my model. And If Jupyter notebook or jupyterhub can only provide interactive backends. Can you please suggest how I can connect the trained model of Colab with the Jupyter notebook in order to use
matplotlib.– Alankrit Mishra
Mar 25 at 3:08
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55324129%2fhow-to-plot-interactive-draw-able-image-using-matplotlib-in-google-colab%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55324129%2fhow-to-plot-interactive-draw-able-image-using-matplotlib-in-google-colab%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
The docs contain several interactive examples for Altair and plotly. (Not sure what's required for matplotlib.)
– Bob Smith
Mar 24 at 17:08
I don't think Google Colab has support for any of the interactive backends (like %matplotlib notebook, or %matplotlib ipympl). Jupyter notebook or jupyterhub may be better suited for that case.
– ImportanceOfBeingErnest
Mar 24 at 22:55
Thanks, @BobSmith but I need the interactive output in Colab, which I guess is not possible.
– Alankrit Mishra
Mar 25 at 3:03
Hi @ImportanceOfBeingErnest, I want to leverage Colab GPU for taining my model. And If Jupyter notebook or jupyterhub can only provide interactive backends. Can you please suggest how I can connect the trained model of Colab with the Jupyter notebook in order to use
matplotlib.– Alankrit Mishra
Mar 25 at 3:08