How can I draw dots so that they appear on top of the tops using matplotlib?

Next, a graph is generated with three data points: (0, 0), (0, 0.5) and (1, 1). Only that part of the plotted points (small circles) that lie inside the graph area is visible, so I see a quarter of the circles in the corners and a semicircle along the left side of the spine.

Is there a trick I can use to make all points fully visible so that they are not cropped in the axis frame?

from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas from matplotlib.figure import Figure fig = Figure() canvas = FigureCanvas(fig) ax = fig.add_subplot(111) ax.plot([0, 0, 1], [0, 0.5, 1], 'o') fig.canvas.print_figure('test.png') 

Edit: The Amro proposal - the obvious approach - is not the preferred approach, as it is for ROC plots (usually drawn with a field from 0 to 1 on both axes). If I could trick matplotlib to get results similar to many in http://www.google.com/search?q=roc+plot that have a rectangular border around 0..1 on both axes, but there are dots drawn on top axis lines, like many of them, which would be optimal.

Edit 2: I assume this can be done using " spinal placement " (new from MPL 0.99), with the plot area being increased slightly, as suggested by Amro, but then the spikes were moved slightly on both O axes. I will experiment with this and publish the answer if it works, although I don’t want to beat it.

+4
source share
3 answers

You can disable cropping either in the chart command or in the executor objects returned by calling "plot".

Firstly, here is a figure with extra large characters, so it’s clear:

alt text

In the plot command you can do

 ax.plot([0, 0, 1], [0, 0.5, 1], 'o', clip_on=False, markersize=20) 

or you could

 p = ax.plot([0, 0, 1], [0, 0.5, 1], 'o', markersize=20) for m in p: m.set_clip_on(False) 
+7
source

You can limit the boundaries of the axes in all directions:

 ax = fig.add_subplot(111, xlim=(-0.1,1.1), ylim=(-0.1,1.1)) 

alt text

+2
source

I combined my idea using the new spine.set_position () function, with Amro's suggestion to expand the boundaries a bit. The following work is only done with matplotlib 1.0 or later, as it relies on a new call to spine.set_bounds (). (I believe that the idea of ​​Amro is needed 1.0 or later, since xlim / ylim kwargs did not do anything for me with 0.99.1.)

 fig = Figure() canvas = FigureCanvas(fig) ax = fig.add_subplot(111, xlim=(-0.1, 1.1), ylim=(-0.1, 1.1)) ax.plot([0, 0, 1], [0, 0.5, 1], 'o') for side in 'left bottom top right'.split(): ax.spines[side].set_position('zero') ax.spines[side].set_bounds(0, 1) canvas.print_figure('test.png') 

I would still be interested to hear if there is a different approach, but I assume that after multi-starving, matplotlib has a major limitation around this area: all data is tightly cut off by the area defined for the axis.

+1
source

All Articles