Comments (6)
I just looked at the example and can confirm what you see.
The reason for the funny look in the legend is that those tiny little herrorbar crosshairs are no MATLAB(R) entity, but composed of a couple of lines each. -- Lines which have no semantic distinction from the actual data lines. What m2t sees is a bunch of lines two of which are to be present in the legend.
Unfortunately, there's little chance this can be fixed in m2t itself. We'd have to teach it what lines to ignore, and right now I cannot think of any sensible criterion.
That said, Pgfplots makes it possible for you to tweak the legend entries. Take a peak at the Pgfplots manual and I'm sure you'll find what you're looking for.
from matlab2tikz.
Thanks a lot for investigating, I will have a look at manually adjusting the legend entries then.
One more note: I have to confess that I haven't had the time to go through and understand the m2t code, so I don't know if the following would make sense and help or not. In MATLAB, if you have the legend handle (let's call it h_leg), you can do
s = get(h_leg, 'userdata');
and get a nice structure with legend information, including the handles to the plots that are shown in the legend. Thus something like
c = get(s.handles(1), 'color');
might for example enable the script to look up the right color of the first legend entry.
from matlab2tikz.
I looked a bit more into the m2t code now and implemented a quick solution that solves my problem (and I hope won't break anything else).
In function drawLine(), I add the following code in the beginning:
% check if the line is included in some legend (note: a figure can have
% multiple legends, e.g. if using subplots)
h_fig = m2t.currentHandles.gcf;
h_legs = [];
for h=get(h_fig, 'children')'
if strcmp(get(h, 'tag'), 'legend')
h_legs(end+1) = h;
end
end
if ~isempty(h_legs)
include_in_legend = false;
for h_leg=h_legs
ud = get(h_leg, 'userdata');
for h=ud.handles'
if (~errorbarMode && h == handle) ||...
(errorbarMode && h == get(handle, 'parent'))
include_in_legend = true;
break;
end
end
end
else
include_in_legend = false;
end
and then modify the checks later in the same function if "forget plot" should be added:
% If the line has been broken up into separate pieces, make sure that
% they appear as one in the legend. The following makes sure that all
% the segments, except for the last one, are discarded from the legend.
if k < length(xDataCell) || ~include_in_legend
myDrawOptions = appendOptions( drawOptions, 'forget plot' );
opts = [ '\n', collapse( myDrawOptions, ',\n' ), '\n' ];
else
opts = [ '\n', collapse( drawOptions, ',\n' ), '\n' ];
end
I hope this can be helpful to someone, or maybe the code can be cleaned up and added in some future release.
from matlab2tikz.
Hi brupp,
sweet idea! I'm implementing something very similar now, should be out soon. Thanks for the suggestion!
from matlab2tikz.
Should be fixed now. Feel free to reopen if necessary.
from matlab2tikz.
Great, thanks!
from matlab2tikz.
Related Issues (20)
- matlab2tikz generates empty tikz-file when creating polarplot HOT 1
- xticklabel style: number format error
- Text from legendflex has vertical position offset HOT 3
- Can matlab2tikz convert bubblecharts to tikz? HOT 1
- workaround for warning "unknown legend location 'layout'" in tiledlayout
- GDX init failed: Could not load shared library libgdxdclib64.dylib: dlopen(libgdxdclib64.dylib, 2): image not found HOT 1
- Error in `formatPgfTickLabels` with loglog plots HOT 1
- matlab2tikz does not know how to handle object with type "implicitfunctionline"
- Error when using bodeplot HOT 1
- Support for sgtitle
- How to simulate audio signal using Uniform Linear Array using MATLAB HOT 1
- Diseño del cerpentin
- add support for plotting polygons? HOT 2
- minor grid style
- Append font style for axis labels
- Spikes in the Latex plot when using Cleanfigure HOT 2
- question about data out of the xlim or ylim
- IMD Grid Finding
- matlab HOT 1
- Levels in contourf HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from matlab2tikz.