Remove Matplotlib Toolbar from the Graph - python

I am drawing a graph in python using Matplotlib library.
I want to remove the whole toolbar from the graph.
which look like this.
i have been trying alot but not able to figure out the way to do it.
kindly direct me to the File/code and suggest me the modifications to be carried out.

You can disable the tool bar via rcParams. Either add (or uncomment) the line
toolbar: None
in your matplotlibrc file or dynamically,
rcParams['toolbar'] = 'None'

Related

How to send Python line graph output through HDMI to another display?

I am working on a project that need me to generate a real time line chart on a separate display.
I'm able to have the real time line chart working on my laptop now but I also want the separate display to show only the line chart (the chart window only), I do not want to make the display as the duplicate of my laptop screen. Is there a way for me to do send the chart through HDMI using Python? Is there any library/ function that would be helpful? If Python won't work, is there any other tool that could be helpful for my case?
Feel free to let me know if you have any question regarding this scenario, any help is appreciated. :)
You can generate a graph with matplotlib. Save it to a specific location with some name.
Then use PyGame/ Tkinter/ PyQt5 to make a "window" to display the image.
Then extend your display. The projector display will have the PyGame/PyQt "window" in full-screen.
I think this is pretty much what you want.

Does it exist an enhanced Toolbar for matplotlib figure?

I'm looking for a toolbar for matplotlib figure that contains more options than the basic one, which is automatically set in pyqt environment.
I already know how to add my own button, but I'm looking for a more advanced Toolbar already coded, that I can used directly.
In Matlab, for instance, it is possible to add points in the panel, or a text directly on the figure from the figure itself.
Outside of the one you're using, I don't think so. Try bokeh. Depending on your environment, ipywidgets may work too.
Hope that helps!

How to stop bokeh from opening a new tab in Jupyter Notebook?

First of all, before this is tagged as duplicate, I have read the other solutions and unfortunately none of them worked for me.
My problem is that I want to display a bokeh plot in Juypter Notebook (and only in Jupyter Notebook), not in a new tab/window.
In the official documentation here I am told that I only need to change
output_file
to
output_notebook
Even though the plot is now displayed inline if I do that, bokeh won't stop also opening a new tab and needlessly displaying the plot there.
Since I'm gonna create lots of plots in my project, it'd be very nice to not always have to close this new tab and return to notebook, but just have it stop creating new tabs, just as it would work with e.g. matplotlib.
What confuses me is that if I load up the official tutorial and enter code there, for example
import numpy as np
x = np.linspace(0, 10, 100)
y = np.exp(x)
p = figure()
p.line(x, y)
show(p)
there is no new tab opened. If I now run the same code locally on my machine's Juypter Notebook, it does open up a new tab.
I've been trying for a while now to fix this, any help would be very much appreciated.
Thanks in advance, Vincent
You need to call output_notebook at the top of your notebook, but only call output_notebook. If you call output_file at all, that activates a persistent mode that saves output to files, and causes show to open new tabs with those files. You would need to call reset_output to clear that persistent mode.
As a convenience, since several users asked for it, if no output mode is supplied, show behaves as though output_file was called as a default. The reason a tab is not opened from the Binder tutorial is because it is not technically possible for code running remotely on Binder server to open a tab on your local browser (which is a very good thing).
Adding an explicit example to #bigreddot's answer:
You might have ran bokeh.io.output_file() somewhere in your notebook, to save noteable graphs. However, now you only want to experiment with some plots quickly to inspect the data.
Simply reset your settings to stop saving to file in any cell in your notebook like so:
import bokeh.io
# this is here only for completeness to clarify where
# the methods are nested (you probably already imported this earlier)
bokeh.io.reset_output()
bokeh.io.output_notebook()
You can activate saving to file again later to keep the interesting graphs.
You can import:
from bokeh.plotting import output_notebook
And call output_notebook before your figures declaration, then you just show the figure using show. See the doc.

How to save figures in a folder with Jupyter Notebook when the plots are produced with an external function that I don't want to modify?

I want to save figures plotted by a function that I don't want to have to touch (because it is an external function, and also because if tomorrow I don't want to save them and just display on the console, I don't want to have to edit the source code again and again). Is it possible to save the figures into a folder from ipython? Whether the figures are plotted in iPython or not is not a concern. I just want to be able to save them in a folder automatically, as they are a lot in number.
I have tried most of the solutions mentioned here, but they don't work - they just save a blank image file.
import matplotlib.pyplot as pl
fig = pl.figure()
external_function(parameters) # this function plots a figure
fig.savefig(r'path\to\folder\image.png') # saves a blank image.png into the folder
fig.savefig must be before show because when you close the figure, it is destroyed and only an empty (will appear blank) figure is saved.
There are several approaches, all of which require a modification of the external function that you don't want to change:
1 - modify the external function by adding a parameter to indicate if the figure must be saved or not, then using a conditional to save the figure or not.
def external function(params, dosave=False):
...
if dosave:
fig.savefig...
fig.show()
2 - modify the external function to return a figure that you can then choose to save prior to displaying it.
3 - Possibly decorate the external function so it saves the figure.
There may be a 'hacky way' to use ipython internals to keep a handle on the figures you are closing, but I don't know it.

Interactive tooltips in matplotlib plot

Is there any way of getting interactive tooltips in a matplotlib plot? For instance, I wanted to get this scatter plot with hovering tooltips (http://mpld3.github.io/examples/scatter_tooltip.html) functionality in my python application, because they are really useful for visualizations. Unfortunately, I do not want to show this in a browser, but integrated in my own python application, is there any way to do this?
Matplotlib can only create static images and animations. If you want something interactive, then the only way you're going to achieve this is by using a module that outputs javascript. I would suggest reading about bokeh.
It is well developed and gaining a lot of traction in the python world as being a good option for creating interactive plots. Here's an example of bokeh's hovertool capability.
Unfortunately, I do not want to show this in a browser, but integrated in my own python application
I'm not sure what your "own python application" is but you're not going to have a fun time making an interactive plot outside of a browser. I would highly suggest going a webapp route using bokeh if interactivity is truly important to you.

Categories

Resources