Confusion Matrix

Hello List.

I'm trying to plot a confusion matrix and I got this far:
http://paste.pocoo.org/show/238332/

Basically what I still want to do is get the ticklabels from the bottom
to the top, have every ticklabel shown and start showing them from the
first not from the second.

I have experimented with this for a while now and don't have all the
code states at hand anymore but basically at several points some of the
above worked but the others didn't or something else (like the axis
length) broke.

Best
Simon

2010/7/16 Simon Friedberger <simon+matplotlib@...3202...>:

Hello List.

I'm trying to plot a confusion matrix and I got this far:
http://paste.pocoo.org/show/238332/

Basically what I still want to do is get the ticklabels from the bottom
to the top, have every ticklabel shown and start showing them from the
first not from the second.

Maybe try to use axes.set_xticks() first, see
http://matplotlib.sourceforge.net/api/axes_api.html#matplotlib.axes.Axes.set_xticks
.

Your code on pocoo is messed up with whitespace. Is that intentional?

Friedrich

Maybe try to use axes.set_xticks() first, see
http://matplotlib.sourceforge.net/api/axes_api.html#matplotlib.axes.Axes.set_xticks
.

I know about that but couldn't find any useful way. Could you be more
specific?

Your code on pocoo is messed up with whitespace. Is that intentional?

Messed up? It looks all good to me.

Regards
Simon

···

On 22:49 Sat 17.07.10, Friedrich Romstedt wrote:

2010/7/18 Simon Friedberger <simon+matplotlib@...3202...>:

Maybe try to use axes.set_xticks() first, see
http://matplotlib.sourceforge.net/api/axes_api.html#matplotlib.axes.Axes.set_xticks
.

I know about that but couldn't find any useful way. Could you be more
specific?

Try to add:

ax.set_xticks(range(0, 10))
ax.set_yticks(range(0, 10))

before the imshow call.

For some reason it must happen before the imshow call and not after,
else the yscaling will change (I don't understand this).

Your code on pocoo is messed up with whitespace. Is that intentional?

Messed up? It looks all good to me.

Sorry, but there is plenty of whitespace at the end of each line when
I copy-paste the code, even in raw format.

hth you,
Friedrich

···

On 22:49 Sat 17.07.10, Friedrich Romstedt wrote:

Thanks for this tip. Apparently there is a necessary order for some calls.
Is this documented anywhere? It seems quite problematic.

Also I have now finished my confusion matrix program:
http://paste.pocoo.org/show/242834/
Comments on the code would be very welcome.

If people like it maybe it could be included in the examples. I think it's a
relatively common usecase.

Regards
Simon

···

On 18:32 Sun 18.07.10, Friedrich Romstedt wrote:

Try to add:
ax.set_xticks(range(0, 10))
ax.set_yticks(range(0, 10))

before the imshow call.

For some reason it must happen before the imshow call and not after,
else the yscaling will change (I don't understand this).

Hi,

In scikits.learn, there is a confusion matrix and in the samples,
there are several plots (scikit-learn.sf.net).

Matthieu

2010/7/16 Simon Friedberger <simon+matplotlib@...3202...>:

···

Hello List.

I'm trying to plot a confusion matrix and I got this far:
http://paste.pocoo.org/show/238332/

Basically what I still want to do is get the ticklabels from the bottom
to the top, have every ticklabel shown and start showing them from the
first not from the second.

I have experimented with this for a while now and don't have all the
code states at hand anymore but basically at several points some of the
above worked but the others didn't or something else (like the axis
length) broke.

Best
Simon

------------------------------------------------------------------------------
This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

--
Information System Engineer, Ph.D.
Blog: http://matt.eifelle.com
LinkedIn: Matthieu Brucher - Quantitative Developer - Squarepoint Capital | LinkedIn

2010/7/29 Simon Friedberger <simon+matplotlib@...3202...>:

Also I have now finished my confusion matrix program:
http://paste.pocoo.org/show/242834/
Comments on the code would be very welcome.

I think you can make use of

axis.set_label_position('top')
axis.set_ticks_position('none')

Friedrich

For some magical reason when I set the ticks_position to none, setting
the label_position to 'top' is ignored.
Did you try this? Is it another command arrangement thing?

···

On 09:26 Thu 29.07.10, Friedrich Romstedt wrote:

axis.set_label_position('top')
axis.set_ticks_position('none')

2010/7/29 Simon Friedberger <simon+matplotlib@...3202...>:

For some magical reason when I set the ticks_position to none, setting
the label_position to 'top' is ignored.
Did you try this? Is it another command arrangement thing?

axis.set_label_position('top')
axis.set_ticks_position('none')

No, I didn't try, it was just a collection of commands, but I was
wrong: .set_label_position() refers to the axis label, this is the
single string labeling all the ticks with their "labels", e.g. "This
is x axis.".

What you will want to use is .set_tick_params(top=True,
labeltop=False, labelbottom=False) .

(But I didn't try this either. :slight_smile: set_ticks_position() is just a
shorthand for .set_tick_params().

Friedrich

···

On 09:26 Thu 29.07.10, Friedrich Romstedt wrote:

That worked indeed but I have uncovered another problem.

It is about the positioning of the rotated labels.
The code is here:
http://paste.pocoo.org/show/246870/

Note that in line 36 I had already remarked about the hack I used. Now I
noticed that if the labels have different lengths rotating them gives
different positions. What I really want to do is rotate about the bottom
of the labels. Can that be done?

Regards
Simon

···

On 09:29 Sat 31.07.10, Friedrich Romstedt wrote:

What you will want to use is .set_tick_params(top=True,
labeltop=False, labelbottom=False) .

I have found a solution. I'm not sure if it's good or intended but the
following works:

for label in xax.get_ticklabels():
  label.set_rotation(45)
  label.set_horizontalalignment('left')

Please comment. Apart from that it's here for people who look for a
solution to the same question.

Best
Simon

···

On 16:00 Fri 06.08.10, Simon Friedberger wrote:

It is about the positioning of the rotated labels.
The code is here:
http://paste.pocoo.org/show/246870/

Note that in line 36 I had already remarked about the hack I used. Now I
noticed that if the labels have different lengths rotating them gives
different positions. What I really want to do is rotate about the bottom
of the labels. Can that be done?

2010/8/8 Simon Friedberger <simon+matplotlib@...3202...>:

I have found a solution. I'm not sure if it's good or intended but the
following works:

for label in xax.get_ticklabels():
label.set_rotation(45)
label.set_horizontalalignment('left')

This is fully intended. Maybe you can compare with the version
attached, I believe my version should have some minor improvement (the
labels are anchored all with the baseline's leftmost point at the
center of the grid cell). I have not tried your version, though.

You got rid of the +0.4 with your solution I believe?

Also, for the previous pocoo version still online there, I had a
problem with the "superduperverylonglabel". It was shiftet to the
left. What is understandable from the point of view that matplotlib
anchored the labels' center point at x + 0.4.

Please comment. Apart from that it's here for people who look for a
solution to the same question.

Yes, I agree fully, but have been busy the past few days :slight_smile:

Friedrich

P.S.: You can also try
http://matplotlib.sourceforge.net/examples/pylab_examples/alignment_test.html
, I believe there was some other manual around also covering the
baseline option, but I cannot find it now.

simon.py (2.75 KB)

The "codex" option on the search page helps with this; you can easily
search for "codex baseline"::

  * the default search page: Search — Matplotlib 3.8.2 documentation

  * what is codex?:
http://matplotlib.sourceforge.net/faq/howto_faq.html#search-examples

  * an example using "codex baseline":
http://matplotlib.sourceforge.net/search.html?q=codex+baseline

Basically, you go to the default mpl homepage or any sub-page, and
from there, click the "Search" link, and then enter "codex YOURPHRASE"
where codex stands for "code example" and will return all code
examples containing your phrase.

JDH

···

On Sun, Aug 8, 2010 at 8:03 PM, Friedrich Romstedt <friedrichromstedt@...287...> wrote:

Yes, I agree fully, but have been busy the past few days :slight_smile:

Friedrich

P.S.: You can also try
http://matplotlib.sourceforge.net/examples/pylab_examples/alignment_test.html
, I believe there was some other manual around also covering the
baseline option, but I cannot find it now.

2010/8/9 John Hunter <jdh2358@...287...>:

···

On Sun, Aug 8, 2010 at 8:03 PM, Friedrich Romstedt > <friedrichromstedt@...287...> wrote:

P.S.: You can also try
http://matplotlib.sourceforge.net/examples/pylab_examples/alignment_test.html
, I believe there was some other manual around also covering the
baseline option, but I cannot find it now.

The "codex" option on the search page helps with this; you can easily
search for "codex baseline"::

* the default search page: Search — Matplotlib 3.8.2 documentation

* what is codex?:
http://matplotlib.sourceforge.net/faq/howto_faq.html#search-examples

* an example using "codex baseline":
Search — Matplotlib 3.8.2 documentation

Thanks, that will be very useful. Actually the page I was looking for was:

http://matplotlib.sourceforge.net/examples/pylab_examples/demo_text_rotation_mode.html?highlight=codex%20baseline

So far,
Friedrich