I'm now embedding matplotlib plot in a simple GUI. During the customization of the plot, I found some displaying issues occurred when I added tool bar under the plot using NavigationToolbar2TkAgg. Now I want to disable displaying coordinate at right side of the bottom of plot when mouse moves around the plot, if we add tool bars at the left side of the bottom. Any idea about this?
Thanks in advance.
Update:
For a figure simply drawn by plt.plot(x,y), the coordinates are displayed at left side of the bottom along with mouse moving as tool bars (like "home", "zoom" etc.) are listed at the top by default. It will be much clearer to view the screen shot at google drive here and I highlighted the coordinates in yellow, which one can find at the bottom left of the image. Thanks GWW and jgysland for reminding me.
You want the opposite of matplotlib values under cursor, but the solution is the same, you need to over-write the format_coord attribute on the Axes object.
ax.format_coord = lambda x, y: ''
should do the trick where ax is a reference to the axes object you care about.
Another option is to sub-class NavigationToolbar2TkAgg and make the set_message function a no-op
class my_toolbar(NavigationToolbar2TkAgg):
def set_message(self, msg):
pass
Related
how can I change the position of the y-axis labels to the right side? The standard is of course on the left side, but I want to have it on the right side.
I can’t find anything in the holoviz panel documentation to it.
I tried to derive it from the position settings of the legend. So, I thought p.y_axis_label_text_align = 'right’ could be right. However, it does not work.
Can anybody help me out or has a Python panel example where the y-axis is located on the right side of the chart tile? Thanks in advance.
The answer depends on the package you are using.
Holoviews
If your figure is created with holoviews, please cheack out the holoviews documentation for axis-positions.
In gerneal
.opts(xaxis='top', yaxis='right')
does the trick.
bokeh
If you are using the the figure of bokeh.plotting, then
p = figure(..., y_axis_location="right", ...)
moves the one y-axis to the right.
In case you want to add a new axis, the twin-axis example shows how to add a LinearAxis.
Have multi-dimension data, for example:
data pic
when i plot x,y chart out. matplot gives the x,y coordinate info at the bottom right corner when one moves the cursor around.
I am trying to add more info to the display, such as info1, info2 etc. on top of the x,y, either at the same corner, or popup when cursor moves on the chart.
Thanks
use libraries Plotly and Cufflinks for interactive charts
Here's a simple solution: use a 3d plot, and use color and size arguments with respect to different values of your other variables. That way, you can display a lot of information very easily.
I am trying to display spectrograms in a Flask application. I use matplotlib for creating the spectrograms and mpld3 for displaying them in an HTML file with the default toolbar.
The problem is that I am not able to zoom into the same region for each spectrogram at the same time.
This is a screenshot of default figure
This is another screenshot that I took after zooming in a little bit on a left top one.
As you can see, all of the y-axes have been changed with the same scale as the left top ones. However, the x-axes of the right top, the left bottom, and the right bottom haven't been changed at all. So what I want to do is to compare those guys with the same scale.
Does anyone have any suggestion such as a better idea to make it possible or maybe the solution for the problem?
I am generating a 3D plot using matplotlib. I want to be able to zoom in on areas of interest. Currently, I am able to pan but not zoom. Looking at the mplot3d API, I learned about can_pan():
Return True if this axes supports the pan/zoom button functionality.
3D axes objects do not use the pan/zoom button.
and can_zoom():
Return True if this axes supports the zoom box button functionality.
3D axes objects do not use the zoom box button.
They both return False (I think can_pan returns False because the axes cannot pan AND zoom both but maybe I am reading the API wrong).
Is there a way to enable Zoom? The API indicates it does not use the buttons. Is there some way to enable zoom or set it so can_pan() and can_zoom() return True?
Here is a snippet of the code:
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
data = np.genfromtxt('data_file.txt')
fig1 = plt.figure()
ax1 = fig1.gca(projection='3d')
ax1.scatter(data[:,0],data[:,1],data[:,2], c='r', marker='.')
plt.show()
ax1.can_zoom()
>>> False
ax1.can_pan()
>>> False
I am using Python 2.7 on an Ubuntu 14.04 64bit desktop version machine with matplotlib installed from the default repositories (I can look the versions up if that is pertinent).
Actually #tcaswell is correct that this functionality doesn't exist and so it returns false. Have you tried zoom-to-rectangle button on the plot window? That works perfectly. If you haven't yet, then refer to the matplotlib instructions on Interactive Navigation.
You can zoom in using two ways:
Clicking on pan/zoom button:
Press the right mouse button to zoom, dragging it to a new position. The x axis will be zoomed in proportionate to the rightward movement and zoomed out proportionate to the leftward movement.
Clicking on zoom-to-rectangle button:
Put your mouse somewhere over and axes and press the left mouse button. Drag the mouse while holding the button to a new location and release.
Instead of zoom functionality, you can control the limit of the axis like
RADIUS = 1.0 # Control this value.
ax1.set_xlim3d(-RADIUS / 2, RADIUS / 2)
ax1.set_zlim3d(-RADIUS / 2, RADIUS / 2)
ax1.set_ylim3d(-RADIUS / 2, RADIUS / 2)
and you see your data in closer view if you define RADIUS variable smaller. In this example you can zoom into and zoom out from the origin.
You can optionally choose other focus point although you need to calculate the appropriate limit to achieve the desired view. Hope this helps.
I'm not sure it works in python2 because I have no such environment.
You could drag scroll wheel on mouse to zoom as well.
I am plotting some scalar data as a contour plot with matplotlib.contourf. On top of it, I am plotting some vector data with matplotlib.arrow. The basic plot has come along OK, but now I need to put a box on the plot with a default-size arrow plus the data value to which it corresponds, so the viewer will know what kind of scale he is looking at. For instance, I need a box with a horizontal arrow of some length and, below that, some text like "10 cm/sec".
First, if anyone can give me a simple approach to this, I would be grateful.
Second, the approach I have tried is to do the contour plot, then plot the arrows, then add a rectangle to the plot like so:
rect=pl.Rectangle((300,70),15,15,fc='white')
pl.gca().add_patch(rect)
and then, finally, put my scale arrow and text on top of this rectangle.
This isn't working because the rectangle patch covers up the contour, but it doesn't cover up the arrows in the plot. Is there a way to move the patch completely "to the front" of everything else?
Got it. Using pylab.quiver and pylab.quiverkey functions. quiver produces a nice vector field with just a few lines of code, and quiverkey makes it easy to produce a scaling vector with text. And, for some reason, the arrows plotted with quiver are indeed covered by my rectangle, so it is easy to make the scaling arrow very visible. There are still some mysteries in all of this for me. If anyone wants to try to clear them up, would be much obliged. But I have a way now to do what I need in this instance.