Hi All
I've been knocking my head against this, and wondered if anyone had any insights.
I've made a plot with the wonderful matplotlib. I've always found it to work brilliantly, and I've found that even without knowing much about it I can get it to do most of the things I've wanted it to do.
Today, I wanted to insert a few arrows onto my graphs to point out some features. They didn't need any text or other annotation. Just the simplest imaginable vertical arrows. Imagine my surprise, when this turned out to be impossible for me to do.
I tried various things with arrow and annotate. With arrow I managed to get a thick vertical line where I wanted the arrow. But I couldn't figure out how to make it look like an arrow. I realised that the arrows it was trying to draw were a lot fancier than I needed, but I tried various combinations and nothing. I feel really stupid at this point.
So let's make it more specific. A set of axes with x running from 200 to 300, and y running from 0.5 to 1.5. I want something that looks like a little arrow pointing down, so the tip is at (250, 1.3) and the tail is at (250,1.45) say.
Any ideas of how this could be done? It must be simple, surely!
The next level of complication (although just achieving the above would cause great joy), is that sometimes I'd like the arrow to go beyond the bounds of the axes. Say (260,1.45) to (260,1.6). Any ideas?
Lastly, can I just impose the arrows on the whole figure, rather than on a specific set of axes, so that I can easily have arrows the same size regardless of the number of subplots and what their scales are? Of course this is the least important, because it can be calculated...
Many thanks!
9 14632 bvdet 2,851
Expert Mod 2GB
According to matplotlib docs, arrow usage is: - arrow(x, y, dx, dy, **kwargs)
which will draw an arrow on specified axis from (x, y) to (x + dx, y + dy). Optional kwargs control the arrow properties. Check out the example source code.
thanks, bvdet. That's what I've been looking at the whole day. So the basic usage, without any optional arguments, is exactly how I managed to get some lines on my graph. And if I made them more angled, I could just make out the arrow head. But unfortunately that's as far as I could take it. I tried fiddling with the key-word arguments (width, and head_width), but I just couldn't make it work. The example is pretty complicated, and unfortunately leaves me none the wiser. There's a much simpler example, which I thought I might have more luck with, which uses annotate. But again, it was unclear from the examples what certain parameters do, and I had no joy trying to fix it.
I guess I'll just keep looking. Thanks anyway.
bvdet 2,851
Expert Mod 2GB
Thanks for the update Glenton. I have never used matplotlib, so I am learning about this with you!
BV
Okay, I've just tried the code in the post - from matplotlib.patches import FancyArrowPatch
-
ax=gca()
-
ax.add_patch(FancyArrowPatch((9,0),(9,0.5),arrowstyle='->',mutation_scale=30))
And it worked brilliantly!
bvdet 2,851
Expert Mod 2GB
Glenton,
You have gotten me interested in matplotlib. I will try it out when I get a chance.
BV
it is rapidly becoming my favourite way to do graphs. I did an animation for the wikipedia article on the quantum hall effect the other day with it (I still need to fix the article when I get some time, and make the graph a bit smaller...)
It seems that this still doesn't work. A simple example:
arrow(0.2,0.2,0.6,0.6)
This should produce a diagonal line with an arrow-head on the end. It produces a diagonal line with no arrow-head.
The example code which explicitly imports FancyArrowPatch didn't work for me, either - it produced absolutely nothing.
Hi. Please post your code, and exactly what happened. Eg when you say nothing, does it mean no graph or no arrow?
Sign in to post your reply or Sign up for a free account.
Similar topics
by: John Hunter |
last post by:
matplotlib is a 2D plotting package for python with a matlab
compatible syntax and output tested under linux and windows platforms.
matplotlib-0.30 is available for download at...
|
by: John Hunter |
last post by:
matplotlib is a 2D plotting library for python. You can use
matplotlib interactively from a python shell or IDE, or embed it in
GUI applications (WX, GTK, and Tkinter). matplotlib supports many...
|
by: Grant Edwards |
last post by:
I downloaded examples/contour_demo.py, and it doesn't run.
I've searched both the user guide and the Wiki for "contour"
and got zero hits.
...
|
by: spross |
last post by:
hi all
i have to use matplotlib on mac os x. on the official site of
matplotlib, i found a link to precompiled python packages for mac os x:
http://pythonmac.org/packages/py24-fat/index.html
...
|
by: Soren |
last post by:
Hi,
I've been trying to embed matplotlib in wxpython. I want to be able to
put a figure (axes) in a wx.Panel and place it somewhere in my GUI.
The GUI should have other panels with buttons etc....
|
by: vajratkarviraj |
last post by:
i hav python2.5, matplotlib0.90.1, and py2exe for python 2.5 all on windows xp... i hav a python program(letsc.py) which uses the matplotlib package... and i want 2 make an exe of it for distribution...
|
by: John Henry |
last post by:
Has anybody been able to create an exe of their python applications
involving matplotlib using pyinstall (ver 1.3)? I am getting a:
RuntimeError: Could not find the matplotlib data files
when...
|
by: PamMish1982 |
last post by:
Hi all,
I have recently started using Python and I am trying to make a GUI out of Tkinter. I am using matplotlib for the graphic purposes. I have to make a exe file from this code. I use py2exe...
|
by: Chriskim |
last post by:
Hi I am having a very difficult time makine executable file using Py2exe. This program uses "matplotlib" to generate graphs and I think this is causing the errors
What extra codes are necessary to...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
| |