I have an assignment that is requiring us to create a dot grid along with a curser that moves up, down, right, left, on the grid when given the command. I can't get my move functions to work along with the grid showing with the updated coordinate. This is what I have so far.
It looks like it might be an import issue or you need to define method for show_grid(x,y). Let me know if this helps!
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.
I've started playing with pyqtgraph plotting line charts.
I have the need to draw specific dots in some section of the lines.
I found that in order for dots to appear on the line,
I need to use symbolBrush when plotting E.g
curve3 = p1.plot(pen=(2,5) , name="trade" , symbolBrush=2)
But the thing is it shows dots on the entire line,
and I can't seem to find a way to draw a dot for specific points / sections.
Assistance would be appreciated
Edit:
For example, In the attached image, assume I only want to draw a dot where marked (1,1) without dots being drawn on the other line breaks.
So, here is an example of what you are looking for. It's a bit "dodgy" in that I'm accessing something inside a PlotDataItem that probably shouldn't be directly accessed, so there is a risk that this code may become non-functional with future updates to pyqtgraph.
That said, I think the risk is reasonably low, it would be easy to update my example to work with whatever changes are made to pyqtgraph, and the example may spark an idea in you that leads to a path that achieves the same thing, without needing to abuse the internals of pyqtgraph.
pw = pg.PlotWidget()
x = np.arange(8)
y = [1,6,2,4,3,5,6,8]
p = pw.plot(x=x, y=y, symbolSize=25)
p.scatter.setData(x=[x[2]],y=[y[2]])
pw.show()
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
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.
I'm using matplotlib in my wx.Frame to draw some arrows and text at a certain position. The number and position of the arrows is based on previously created data.
I do some calculations but basically it's like this:
arrow = primer
for each primer:
draw one arrow at position y - 0.05 to the previos arrow (primer_y - 0.05).
The x position of the arrow comes from the data, which is calculated and scaled (not so important know, it's just to now where the arrow should be at primer_x).
Everything works fine until I have many arrows to draw. E.g. in my code example the data contain 62 arrows, where 18 are drawn correctly, the next 3 are missing but the text is there and the rest is completly missing.
Does anyone knows what could be the problem? I tried allready to change the FigureSize but it's only stretch the arrows.
Here's a quick and dirty working example, data is included in the code:
http://pastebin.com/7mQmZm2c
Any help is highly appreciated!
Thanks in advance!
Stefanie
Stick
print((primer_x+0.06, primer_y))
inside the loop. You'll find that the arrows cease to be drawn when
primer_y becomes negative.
Don't draw the arrows with self.axes.annotate while labeling the
arrow with self.fig.text. The axis and the figure use different
coordinate systems. Changing self.fig.text to self.axes.text
will allow you to use the same coordinate system, which will make it
easier for you to position the text under the arrows.
There are far too many
hard-coded numbers ("magic numbers") in your code. It makes it very
hard to fix because when one number changes, the rest to do not change
in a logical way along with it. If you can use formulas to define
the relationship between some of those magic numbers, your life will
be a lot easier.
For example, if you change the for-loop to
for primer,primer_y in zip(data,np.linspace(0.95,0.0,len(data))):
instead of decrementing primer_y by a fixed amount with each pass through the loop, then primer_y will automatically space itself between 0.95 down to 0.0 no matter how many items there are in data.
If you find the arrows are squished (vertically), you can expand the
figure by changing the figsize on this line:
self.fig = matplotlib.figure.Figure(figsize=(20, 30), facecolor='white')