Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

plotting markers on top of axes

I am tying to make a (x,y) scatter plot using numpy. Right now the axes start from (0,0) and extend to align with the range of the data. I need to plot two points which lie on the x=0 line.

Currently it appears the symbols are being drawn before the axes, and subsequently are being truncated by the axes. I would like this to appear on top of the axes. I believe I can do something with a 'label' however I cannot find any method to make this work.

The markers are somewhat visible, however they are a decently crucial component of the visualization. If someone has a work around this would be wonderful.

like image 841
wsavran Avatar asked Feb 09 '12 22:02

wsavran


People also ask

What does ax ax do?

plot(...,ax=ax) dictates that plt draws the plots into ax , which is an axis instance. This is used when you have several active axis instances.

How do I draw a square marker in matplotlib?

To make hollow square marks with matplotlib, we can use marker 'ks', markerfacecolor='none', markersize=15, and markeredgecolor=red.


2 Answers

You can turn off the clip flag of the line object created by plt.plot.

import numpy as np
import matplotlib.pyplot as plt
x = np.array([0,1,2,3,4,5,6])
y = np.array([0,2,0,4.5,0.5,2,3])

line = plt.plot(x,y,'o')[0]
line.set_clip_on(False)
plt.show()

enter image description here

like image 177
HYRY Avatar answered Sep 28 '22 08:09

HYRY


To actually make the markers appear on top of the axes, you can use zorder:

import numpy as np
import matplotlib.pyplot as plt
x = np.array([0,1,2,3,4,5,6])
y = np.array([0,2,0,4.5,0.5,2,3])

plt.plot(x, y, 'o', zorder=10, clip_on=False)
plt.xlim(0, 6)
plt.ylim(0, 4.5)
plt.show()

The result

like image 30
ondra.cifka Avatar answered Sep 28 '22 10:09

ondra.cifka