Giter Site home page Giter Site logo

Comments (6)

nschloe avatar nschloe commented on May 30, 2024

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.

brupp avatar brupp commented on May 30, 2024

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.

brupp avatar brupp commented on May 30, 2024

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.

nschloe avatar nschloe commented on May 30, 2024

Hi brupp,
sweet idea! I'm implementing something very similar now, should be out soon. Thanks for the suggestion!

from matlab2tikz.

nschloe avatar nschloe commented on May 30, 2024

Should be fixed now. Feel free to reopen if necessary.

from matlab2tikz.

brupp avatar brupp commented on May 30, 2024

Great, thanks!

from matlab2tikz.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.