Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Draw arrow outside plot in Matplotlib

I have the following gridded plot, and would like to draw an arrow (shown in blue using MS paint). How can I do it through matplotlib? I do not know of any command to do it.

enter image description here

like image 433
user308827 Avatar asked May 28 '14 22:05

user308827


People also ask

How do I create an arrow in Matplotlib?

Plot x and y with color=red and linewidth = 1. Use arrow method to add an arrow to the axes. The first two values in the arguments are the coordinates of the arrow base and the next two values are for the length of the arrow along X and Y direction. To display the figure, use show() method.

Can I put legend outside plot Matplotlib?

Matplotlib set legend outside plot In Matplotlib, to set a legend outside of a plot you have to use the legend() method and pass the bbox_to_anchor attribute to it. We use the bbox_to_anchor=(x,y) attribute. Here x and y specify the coordinates of the legend.


2 Answers

import matplotlib.pyplot as plt

fg = plt.figure(1);
fg.clf();
ax = fg.add_subplot(1,1,1)
ax.annotate('', xy=(0, -0.1), xycoords='axes fraction', xytext=(1, -0.1), 
            arrowprops=dict(arrowstyle="<->", color='b'))
ax.grid(True)
fg.canvas.draw()

gives enter image description here

like image 136
Dietrich Avatar answered Sep 20 '22 10:09

Dietrich


Use clip_on = False in ax.arrow

like image 26
Flo Avatar answered Sep 21 '22 10:09

Flo