how do I specify the line join and cap style?

Is it possible to control the join and cap styles of lines and
patches? Is there an example for this? I'm trying to add a scale
marker to a plot, but lines have rounded ends by default, so I'm
currently changing these manually in Inkscape to miter join and butt
cap. Here is a minimal example, based on the code here:

import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1.anchored_artists import AnchoredSizeBar

def add_sizebar(ax, size):
  asb = AnchoredSizeBar(ax.transData,
     size,
     str(size),
     loc=8,
     pad=0.1, borderpad=0.5, sep=5,
     frameon=False)
  ax.add_artist(asb)

add_sizebar(plt.gca(), 0.5)

plt.draw()
plt.show()

What I'd like is a 2pt wide line with butt-style cap ends,

thanks,
Gary

It seems that there is no option to change join and cap style for
patches (only lines have them).
While there could be other ways, one workaround is to use patheffect.

Below is a modified version of your example.

Meanwhile, I think the situation needs to be fixed, i.e., Patches
should implement set_capstyle and set_joinstyle. Can you file a
feature request on the tracker?

Regards,

-JJ

import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1.anchored_artists import AnchoredSizeBar

from matplotlib.patheffects import Stroke

def add_sizebar(ax, size):
asb = AnchoredSizeBar(ax.transData,
    size,
    str(size),
    loc=8,
    pad=0.1, borderpad=0.5, sep=5,
    frameon=False)
ax.add_artist(asb)

mypatch = asb.size_bar.get_children()[0]
mypatch.set_path_effects([Stroke(joinstyle='miter',
                                  capstyle='butt')]) # override
joinstyle and capstyle

add_sizebar(plt.gca(), 0.5)

plt.draw()
plt.show()

···

On Mon, Dec 13, 2010 at 9:16 AM, gary ruben <gruben@...636...> wrote:

Is it possible to control the join and cap styles of lines and
patches? Is there an example for this? I'm trying to add a scale
marker to a plot, but lines have rounded ends by default, so I'm
currently changing these manually in Inkscape to miter join and butt
cap. Here is a minimal example, based on the code here:

import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1.anchored_artists import AnchoredSizeBar

def add_sizebar(ax, size):
asb = AnchoredSizeBar(ax.transData,
size,
str(size),
loc=8,
pad=0.1, borderpad=0.5, sep=5,
frameon=False)
ax.add_artist(asb)

add_sizebar(plt.gca(), 0.5)

plt.draw()
plt.show()

What I'd like is a 2pt wide line with butt-style cap ends,

thanks,
Gary

------------------------------------------------------------------------------
Oracle to DB2 Conversion Guide: Learn learn about native support for PL/SQL,
new data types, scalar functions, improved concurrency, built-in packages,
OCI, SQL*Plus, data movement tools, best practices and more.
http://p.sf.net/sfu/oracle-sfdev2dev
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Thanks for the workaround JJ. I've filed a feature request,

Gary

···

On Mon, Dec 13, 2010 at 9:54 PM, Jae-Joon Lee <lee.j.joon@...287...> wrote:

It seems that there is no option to change join and cap style for
patches (only lines have them).
While there could be other ways, one workaround is to use patheffect.

Below is a modified version of your example.

Meanwhile, I think the situation needs to be fixed, i.e., Patches
should implement set_capstyle and set_joinstyle. Can you file a
feature request on the tracker?

Regards,

-JJ

import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1.anchored_artists import AnchoredSizeBar

from matplotlib.patheffects import Stroke

def add_sizebar(ax, size):
asb = AnchoredSizeBar(ax.transData,
size,
str(size),
loc=8,
pad=0.1, borderpad=0.5, sep=5,
frameon=False)
ax.add_artist(asb)

mypatch = asb.size_bar.get_children()[0]
mypatch.set_path_effects([Stroke(joinstyle='miter',
capstyle='butt')]) # override
joinstyle and capstyle

add_sizebar(plt.gca(), 0.5)

plt.draw()
plt.show()

On Mon, Dec 13, 2010 at 9:16 AM, gary ruben <gruben@...636...> wrote:

Is it possible to control the join and cap styles of lines and
patches? Is there an example for this? I'm trying to add a scale
marker to a plot, but lines have rounded ends by default, so I'm
currently changing these manually in Inkscape to miter join and butt
cap. Here is a minimal example, based on the code here:

import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1.anchored_artists import AnchoredSizeBar

def add_sizebar(ax, size):
asb = AnchoredSizeBar(ax.transData,
size,
str(size),
loc=8,
pad=0.1, borderpad=0.5, sep=5,
frameon=False)
ax.add_artist(asb)

add_sizebar(plt.gca(), 0.5)

plt.draw()
plt.show()

What I'd like is a 2pt wide line with butt-style cap ends,

thanks,
Gary

------------------------------------------------------------------------------
Oracle to DB2 Conversion Guide: Learn learn about native support for PL/SQL,
new data types, scalar functions, improved concurrency, built-in packages,
OCI, SQL*Plus, data movement tools, best practices and more.
http://p.sf.net/sfu/oracle-sfdev2dev
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users