Hi, Is there some way to add support for latex symbols as markers? I think it would be an extension of the current methods for plotting markers- since I dont think all the color, edge, line style etc properties would be relevant (or even possible). However, it would allow arbitrary symbols (at least whatever latex can do) to be used, which would be really useful. The current marker set is fine for most simple plots- but when there are a few different symbols it quickly becomes tricky to find a set which can easily be distinguished from each other. The other problem is that when preparing a graph for publication, it is occasionally necessary to be able to refer to or quote the symbols in the caption or the main text- and latex symbols in the graphs would make this look a bit better. I've had a quick look at how the marker symbols are implemented, and it is my impression that it would be reasonably hard to implement a new symbol of choice. On the other hand, since I am already using latex to produce all the text in the graph, it seems it should be fairly straightforward (with some careful attention to the positioning...) to use the same text-drawing code which is used for the legend, axes labels etc, to put the markers on the plot. Is there any interest in this? thanks, tcb
That's a very interesting idea. I actually think that with the recent textpath functionality that Jae-Joon added, we may be able to tie text and markers together without too much pain. Then it can advantage of all the performance optimizations in draw_markers. Each of the marker styles now contains a function that draws a path for the marker and then passes that to draw_marker. We could add one that draws an arbitrary text path, and then passes that along. I propose that Line.set_marker supports a new marker style "$...$" which would render whatever "..." is as math text. Were you offering to try to produce a patch yourself? Either way, it would be great to file an enhancement request in the tracker so this idea doesn't get lost. It's a good one. Mike tcb wrote: > Hi, > > Is there some way to add support for latex symbols as markers? > > I think it would be an extension of the current methods for plotting > markers- since I dont think all the color, edge, line style etc > properties would be relevant (or even possible). However, it would > allow arbitrary symbols (at least whatever latex can do) to be used, > which would be really useful. > > The current marker set is fine for most simple plots- but when there > are a few different symbols it quickly becomes tricky to find a set > which can easily be distinguished from each other. The other problem > is that when preparing a graph for publication, it is occasionally > necessary to be able to refer to or quote the symbols in the caption > or the main text- and latex symbols in the graphs would make this look > a bit better. > > I've had a quick look at how the marker symbols are implemented, and > it is my impression that it would be reasonably hard to implement a > new symbol of choice. On the other hand, since I am already using > latex to produce all the text in the graph, it seems it should be > fairly straightforward (with some careful attention to the > positioning...) to use the same text-drawing code which is used for > the legend, axes labels etc, to put the markers on the plot. > > Is there any interest in this? > > thanks, > > tcb > > ------------------------------------------------------------------------------ > Come build with us! The BlackBerry(R) Developer Conference in SF, CA > is the only developer event you need to attend this year. Jumpstart your > developing skills, take BlackBerry mobile applications to market and stay > ahead of the curve. Join us from November 9 - 12, 2009. Register now! > http://p.sf.net/sfu/devconference > _______________________________________________ > Matplotlib-devel mailing list > Mat...@li... > https://lists.sourceforge.net/lists/listinfo/matplotlib-devel > -- Michael Droettboom Science Software Branch Operations and Engineering Division Space Telescope Science Institute Operated by AURA for NASA
Hi Mike, I'm not sure about the textpath functionality. Most of the 'easy' marker types have been specified already (triangles, squares etc). Are the latex symbols defined somewhere that you could easily extract a path description of them, and then pass that to the textpath code you have? This would be perfect, since you could then apply the properties changes already there (like color, size, linewidth etc), and you wouldnt necessarily need latex to render the markers. Even if you could manage to make a path description for (all) the markers, they might not exactly correspond to the latex symbols which would be one of the main aims- for eg. using text.usetex with the pdf backend you could match the fonts in your graph to your latex document and it would all look very nice ;) I agree that the best approach would be to make a new marker style '$...$' and pass the string inside to whatever renders the math text. I hadn't consider making a patch myself- but perhaps I'll take a look and see if something can be done (any pointers on the use of the math text code would be appreciated...)- either way I will file an enhancement request to keep track of it. thanks, tcb On Mon, Oct 26, 2009 at 1:03 PM, Michael Droettboom <md...@st...> wrote: > That's a very interesting idea. I actually think that with the recent > textpath functionality that Jae-Joon added, we may be able to tie text and > markers together without too much pain. Then it can advantage of all the > performance optimizations in draw_markers. Each of the marker styles now > contains a function that draws a path for the marker and then passes that to > draw_marker. We could add one that draws an arbitrary text path, and then > passes that along. I propose that Line.set_marker supports a new marker > style "$...$" which would render whatever "..." is as math text. > > Were you offering to try to produce a patch yourself? Either way, it would > be great to file an enhancement request in the tracker so this idea doesn't > get lost. It's a good one. > > Mike > > tcb wrote: >> >> Hi, >> >> Is there some way to add support for latex symbols as markers? >> >> I think it would be an extension of the current methods for plotting >> markers- since I dont think all the color, edge, line style etc >> properties would be relevant (or even possible). However, it would >> allow arbitrary symbols (at least whatever latex can do) to be used, >> which would be really useful. >> >> The current marker set is fine for most simple plots- but when there >> are a few different symbols it quickly becomes tricky to find a set >> which can easily be distinguished from each other. The other problem >> is that when preparing a graph for publication, it is occasionally >> necessary to be able to refer to or quote the symbols in the caption >> or the main text- and latex symbols in the graphs would make this look >> a bit better. >> >> I've had a quick look at how the marker symbols are implemented, and >> it is my impression that it would be reasonably hard to implement a >> new symbol of choice. On the other hand, since I am already using >> latex to produce all the text in the graph, it seems it should be >> fairly straightforward (with some careful attention to the >> positioning...) to use the same text-drawing code which is used for >> the legend, axes labels etc, to put the markers on the plot. >> >> Is there any interest in this? >> >> thanks, >> >> tcb >> >> >> ------------------------------------------------------------------------------ >> Come build with us! The BlackBerry(R) Developer Conference in SF, CA >> is the only developer event you need to attend this year. Jumpstart your >> developing skills, take BlackBerry mobile applications to market and stay >> ahead of the curve. Join us from November 9 - 12, 2009. Register now! >> http://p.sf.net/sfu/devconference >> _______________________________________________ >> Matplotlib-devel mailing list >> Mat...@li... >> https://lists.sourceforge.net/lists/listinfo/matplotlib-devel >> > > -- > Michael Droettboom > Science Software Branch > Operations and Engineering Division > Space Telescope Science Institute > Operated by AURA for NASA > >
tcb wrote: > Hi Mike, > > I'm not sure about the textpath functionality. Most of the 'easy' > marker types have been specified already (triangles, squares etc). Are > the latex symbols defined somewhere that you could easily extract a > path description of them, and then pass that to the textpath code you > have? This would be perfect, since you could then apply the properties > changes already there (like color, size, linewidth etc), and you > wouldnt necessarily need latex to render the markers. > > Even if you could manage to make a path description for (all) the > markers, they might not exactly correspond to the latex symbols which > would be one of the main aims- for eg. using text.usetex with the pdf > backend you could match the fonts in your graph to your latex document > and it would all look very nice ;) > > I agree that the best approach would be to make a new marker style > '$...$' and pass the string inside to whatever renders the math text. > > I hadn't consider making a patch myself- but perhaps I'll take a look > and see if something can be done (any pointers on the use of the math > text code would be appreciated...)- either way I will file an > enhancement request to keep track of it. > The functionality in textpath.py is able to turn any text (including math with the internal render and externally-rendered LaTeX) into a path on-the-fly. It should exactly match the rest of the text, as long as the usetex option is passed along correctly. Look at textpath.text_to_path.get_text_path: convert text *s* to path (a tuple of vertices and codes for matplotlib.math.Path). *prop* font property *s* text to be converted *usetex* If True, use matplotlib usetex mode. *ismath* If True, use mathtext parser. Effective only if usetex == False. There's an example of its usage at the bottom of the same file. It would be great if you wanted to look into this further. Let me know if I can provide any more pointers. Mike > thanks, > > tcb > > > > On Mon, Oct 26, 2009 at 1:03 PM, Michael Droettboom <md...@st...> wrote: > >> That's a very interesting idea. I actually think that with the recent >> textpath functionality that Jae-Joon added, we may be able to tie text and >> markers together without too much pain. Then it can advantage of all the >> performance optimizations in draw_markers. Each of the marker styles now >> contains a function that draws a path for the marker and then passes that to >> draw_marker. We could add one that draws an arbitrary text path, and then >> passes that along. I propose that Line.set_marker supports a new marker >> style "$...$" which would render whatever "..." is as math text. >> >> Were you offering to try to produce a patch yourself? Either way, it would >> be great to file an enhancement request in the tracker so this idea doesn't >> get lost. It's a good one. >> >> Mike >> >> tcb wrote: >> >>> Hi, >>> >>> Is there some way to add support for latex symbols as markers? >>> >>> I think it would be an extension of the current methods for plotting >>> markers- since I dont think all the color, edge, line style etc >>> properties would be relevant (or even possible). However, it would >>> allow arbitrary symbols (at least whatever latex can do) to be used, >>> which would be really useful. >>> >>> The current marker set is fine for most simple plots- but when there >>> are a few different symbols it quickly becomes tricky to find a set >>> which can easily be distinguished from each other. The other problem >>> is that when preparing a graph for publication, it is occasionally >>> necessary to be able to refer to or quote the symbols in the caption >>> or the main text- and latex symbols in the graphs would make this look >>> a bit better. >>> >>> I've had a quick look at how the marker symbols are implemented, and >>> it is my impression that it would be reasonably hard to implement a >>> new symbol of choice. On the other hand, since I am already using >>> latex to produce all the text in the graph, it seems it should be >>> fairly straightforward (with some careful attention to the >>> positioning...) to use the same text-drawing code which is used for >>> the legend, axes labels etc, to put the markers on the plot. >>> >>> Is there any interest in this? >>> >>> thanks, >>> >>> tcb >>> >>> >>> ------------------------------------------------------------------------------ >>> Come build with us! The BlackBerry(R) Developer Conference in SF, CA >>> is the only developer event you need to attend this year. Jumpstart your >>> developing skills, take BlackBerry mobile applications to market and stay >>> ahead of the curve. Join us from November 9 - 12, 2009. Register now! >>> http://p.sf.net/sfu/devconference >>> _______________________________________________ >>> Matplotlib-devel mailing list >>> Mat...@li... >>> https://lists.sourceforge.net/lists/listinfo/matplotlib-devel >>> >>> >> -- >> Michael Droettboom >> Science Software Branch >> Operations and Engineering Division >> Space Telescope Science Institute >> Operated by AURA for NASA >> >> >> > > ------------------------------------------------------------------------------ > Come build with us! The BlackBerry(R) Developer Conference in SF, CA > is the only developer event you need to attend this year. Jumpstart your > developing skills, take BlackBerry mobile applications to market and stay > ahead of the curve. Join us from November 9 - 12, 2009. Register now! > http://p.sf.net/sfu/devconference > _______________________________________________ > Matplotlib-devel mailing list > Mat...@li... > https://lists.sourceforge.net/lists/listinfo/matplotlib-devel > -- Michael Droettboom Science Software Branch Operations and Engineering Division Space Telescope Science Institute Operated by AURA for NASA
Hi Mike, Sorry the long delay in replying to your mail. The changes look good, and it seems to produce good output. There is just one small change I would make- since the markers are not quite properly centered on the points: Index: lib/matplotlib/lines.py =================================================================== --- lib/matplotlib/lines.py (revision 8075) +++ lib/matplotlib/lines.py (working copy) @@ -898,7 +898,7 @@ height = ymax - ymin max_dim = max(width, height) path_trans = Affine2D() \ - .translate(0.5 * -width, 0.5 * -height) \ + .translate(-xmin+0.5 * -width, -ymin+0.5 * -height)\ .scale((renderer.points_to_pixels(self.get_markersize()) / max_dim)) On Tue, Dec 22, 2009 at 4:44 PM, Michael Droettboom <md...@st...> wrote: > It's been a while -- just curious if you've had any more thoughts on this. > I'm considering committing your changes + my suggestions, since what's > there is working pretty well. > > Mike > > tcb wrote: > > >> >> On Mon, Nov 2, 2009 at 3:47 PM, Michael Droettboom <md...@st...<mailto: >> md...@st...>> wrote: >> >> Thanks for all this work. It looks great. >> >> Do you mind if we bring this conversation back to the list? I >> think others may have some additional feedback, but I don't want >> to Cc the list without your permission. >> >> >> >> >> >> Hi Mike, >> >> sure- the discussion should go back to the list- I thought it might be >> better to get your feedback on it first. >> >> your comments are interesting, and I'll take a closer look later on >> today... >> >> tcb >> > > -- > Michael Droettboom > Science Software Branch > Operations and Engineering Division > Space Telescope Science Institute > Operated by AURA for NASA > >
Good point. Fixed in r8076. Cheers, Mike tcb wrote: > Hi Mike, > > Sorry the long delay in replying to your mail. > > The changes look good, and it seems to produce good output. > > There is just one small change I would make- since the markers are not > quite properly centered on the points: > > Index: lib/matplotlib/lines.py > =================================================================== > --- lib/matplotlib/lines.py (revision 8075) > +++ lib/matplotlib/lines.py (working copy) > @@ -898,7 +898,7 @@ > height = ymax - ymin > max_dim = max(width, height) > path_trans = Affine2D() \ > - .translate(0.5 * -width, 0.5 * -height) \ > + .translate(-xmin+0.5 * -width, -ymin+0.5 * -height)\ > .scale((renderer.points_to_pixels(self.get_markersize()) > / max_dim)) > > > > On Tue, Dec 22, 2009 at 4:44 PM, Michael Droettboom <md...@st... > <mailto:md...@st...>> wrote: > > It's been a while -- just curious if you've had any more thoughts > on this. I'm considering committing your changes + my > suggestions, since what's there is working pretty well. > > Mike > > tcb wrote: > > > > On Mon, Nov 2, 2009 at 3:47 PM, Michael Droettboom > <md...@st... <mailto:md...@st...> > <mailto:md...@st... <mailto:md...@st...>>> wrote: > > Thanks for all this work. It looks great. > > Do you mind if we bring this conversation back to the list? I > think others may have some additional feedback, but I don't > want > to Cc the list without your permission. > > > > > > Hi Mike, > > sure- the discussion should go back to the list- I thought it > might be better to get your feedback on it first. > > your comments are interesting, and I'll take a closer look > later on today... > > tcb > > > -- > Michael Droettboom > Science Software Branch > Operations and Engineering Division > Space Telescope Science Institute > Operated by AURA for NASA > > -- Michael Droettboom Science Software Branch Operations and Engineering Division Space Telescope Science Institute Operated by AURA for NASA