Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fixing matplotlib plot

In matplotlib I like to customize my plots by shifting the spines from the origin, for example:

plot(range(10), marker='o', ms=20)

#customize axes
axes = gca()
axes.spines['right'].set_color('none')
axes.spines['top'].set_color('none')
axes.xaxis.set_ticks_position('bottom')
axes.spines['bottom'].set_position(('axes', -0.05))
axes.yaxis.set_ticks_position('left')
axes.spines['left'].set_position(('axes', -0.05))
axes.tick_params(axis='x', direction='out')
axes.tick_params(axis='y', direction='out')

enter image description here

Question:

What can I do to avoid my markers being cut at the borders?

like image 402
elyase Avatar asked Sep 12 '13 13:09

elyase


2 Answers

You have to turn off clipping by adding clip_on=False to your plot command:

import numpy as np
import matplotlib.pyplot as plt

plt.plot(range(10), marker='o', ms=20, clip_on=False)

axes = plt.gca()
axes.spines['right'].set_color('none')
axes.spines['top'].set_color('none')
axes.xaxis.set_ticks_position('bottom')
axes.spines['bottom'].set_position(('axes', -0.05))
axes.yaxis.set_ticks_position('left')
axes.spines['left'].set_position(('axes', -0.05))
axes.tick_params(axis='x', direction='out')
axes.tick_params(axis='y', direction='out')

plt.show()

which produces: result picture

like image 55
David Zwicker Avatar answered Oct 17 '22 05:10

David Zwicker


from pylab import *
plot(range(10), marker='o', ms=20)

#customize axes
axes = gca()

axes.spines['right'].set_color('none')
axes.spines['top'].set_color('none')
axes.xaxis.set_ticks_position('bottom')
axes.spines['bottom'].set_position(('axes', -0.05))
axes.yaxis.set_ticks_position('left')
axes.spines['left'].set_position(('axes', -0.05))
axes.tick_params(axis='x', direction='out')
axes.tick_params(axis='y', direction='out')
axes.spines['bottom'].set_smart_bounds(True)
axes.spines['left'].set_smart_bounds(True)
axes.set_xlim(-0.5, 9.5)
axes.set_ylim(-0.5, 9.5)
axes.set_xticks(range(10))
axes.set_yticks(range(10))

enter image description here

like image 33
Viktor Kerkez Avatar answered Oct 17 '22 06:10

Viktor Kerkez