Matplotlib: Легенда, не отображенная правильно

Это сделано специально, поэтому вам придется самостоятельно отслеживать состояние. Но это определенно остановит Alt от достижения MenuStrip.

Это низкоуровневая фильтрация клавиатуры, поэтому вам придется решить, что делать, когда Alt нажата полностью самостоятельно.

Вы также можете изменить условное выражение для проверки на Alt плюс некоторое состояние .

Короче говоря, возврат true из PreFilterMesssage остановит его доступ к вашему приложению.

static void Main()
{
    //...SNIP...
    Application.AddMessageFilter(new AltFilter());
    //...SNIP...
}

public class AltFilter : IMessageFilter
{
    private static ushort WM_SYSKEYDOWN = 0x0104;

    public bool PreFilterMessage(ref Message m)
    {
        if (m.Msg == WM_SYSKEYDOWN && Control.ModifierKeys == Keys.Alt)
        {
            //Do your own special thing instead
            return true;
        }
        return false;
    }
}
5
задан bayer 16 May 2009 в 13:02
поделиться

1 ответ

It would help to have a self-contained example, possibly with made-up data, so people can run it right away. Here's a self-contained example modified from what you posted that works fine for me in ipython -pylab, with a recent svn revision of Matplotlib; I think some legend-related bugs have been fixed recently.

colors = (i + j for j in 'o<.' for i in 'bgrcmyk')
labels = 'one two three four five six seven eight nine ten'.split()
x = linspace(0, 2*pi, 3000)
d = (2+random((2,3000))) * c_[sin(x), cos(x)].T
for i, l, c  in zip(range(10), labels, colors):
    start, stop = i * 300, (i + 1) * 300
    plot(d[0, start:stop], d[1, start:stop], c, label=l)
legend(loc='lower left')
show()

And here's what I get:

example figure http://www.iki.fi/jks/tmp/legend.png

Assuming the bug is related to the auto-legend feature, you might be able to work around it by being explicit about what you want in the legend:

colors = (i + j for j in 'o<.' for i in 'bgrcmyk')
labels = 'one two three four five six seven eight nine ten'.split()
x = linspace(0, 2*pi, 3000)
d = (2+random((2,3000))) * c_[sin(x), cos(x)].T
lg = []
for i, l, c  in zip(range(10), labels, colors):
    start, stop = i * 300, (i + 1) * 300
    handle = plot(d[0, start:stop], d[1, start:stop], c, label=l)
    lg.append(handle)
legend(lg, labels, loc='lower left')
show()
3
ответ дан 15 December 2019 в 06:34
поделиться
Другие вопросы по тегам:

Похожие вопросы: