-
-
Notifications
You must be signed in to change notification settings - Fork 490
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
matrix plot is upside down and should wrap more matplotlib options #9740
Comments
comment:1
oh, and it also makes axes=False by default, since it looked really silly having axes and this patch also shifts the matrix by 0.5 so it is centered in the plot. |
comment:2
CCing people that might be interested in reviewing this. |
comment:3
In what sense were the matrix plots wrong before? I'm a little confused - the matrix plots I used in number theory seemed to be ok. Also, what matrix plots have axes? The ones I make only have frames, which look quite nice (except for being labeled wrong). Anyway, posting a picture of "before" and "after" that is very clear would be helpful before one takes the time to wade through the mpl code :) #2189 is related, though I don't know if this fixes all the issues mentioned there (i.e. labeling). |
comment:4
Before:
You're right that #2189 is related, but that patch will have to be rewritten so much that it's probably easiest to write it from scratch. Thanks for pointing out the patch, though. You're also right that we are solving a different problem here. This patch does not fix the issue there. |
comment:5
Replying to @jasongrout:
I don't remember seeing that.
Huh, that is weird, because I definitely didn't have that experience. Attached is a screenshot of what I get. The top row is all the powers of 1 mod 7 (which are all 1), and the left row is all the 0th powers of a mod 7 (which are all 1). The right row is Fermat's Little Theorem, that the 6th powers are also 1 mod 7. The matrix itself is
I feel like I must be missing something. |
The matrix in an interact for p=7 |
comment:6
Attachment: Screen shot 2010-08-13 at 11.52.45 AM.png Could you try the following two plots? matrix_plot(identity_matrix(100)) matrix_plot(identity_matrix(100, sparse=True)) |
comment:7
(that is before the patch, of course...) |
comment:8
Looks fine, diagonal is from upper left to lower right, like the matrix. 0 (lowest input) is black, 1 (highest input) is white, I think this is as usual. With cmap='jet' I get something I like :) What do you get for this one?
Yikes! Two issues. First, it is definitely flipped. Second, what's up with the colors? I get white for the off-diagonal zeros and blue for the diagonal. My diagnosis: something going on with all that special code for sparse matrices. And now I see what you mean about the axes showing up. I thought that was just part of the frame because my matrices tend to have blue or black around the edges, since the values are one! Good catch with making axes=False in the future. |
comment:9
After the patch, the labels are corrected. The issue of flipping the matrix is also affected by a matplotlibrc variable, so you might have the "correct" value of origin='upper'. Of course, this is ignored for sparse matrices. That patch corrects all this so that things are consistent. For sparse matrices---the correct picture is whote for off-diagonal and blue for diagonal. That uses spy underneath, which does not plot zero entries, which is exactly what you want for sparse matrices. |
comment:10
Got it. And sure enough, in my top directory (i.e., above my user account) there is one, probably placed there eons ago by some primitive Sage installation, with
Is that it? I hate to be picky, but I have another question.
Should the first word in the second line be 'left'? And if not, please explain. |
comment:11
Yep, that's it. And yes, you're right about the doc correction. New patch coming up. |
comment:12
I should have made that a separate patch; sorry. The only change is that one word 'right'->'left' |
comment:13
A new version of the patch that:
|
comment:14
Just one more enhancement to bring sparse plotting in line with dense plotting: we were automatically converting to floating point numbers in the dense case, which allowed plotting matrices over finite fields, for example. The coerce-float patch enables this for sparse matrices as well. |
comment:15
I'm rebasing this for 4.6.alpha1 momentarily... |
comment:16
I've rebased to 4.6.alpha1 and combined the two patches. kcrisman: can you review this? |
Attachment: trac-9740-matrixplot.patch.gz apply only this patch; rebased to 4.6.alpha1 |
comment:18
Explain
in all cases - will this make anything different, particularly the Explain
I assume this makes it so that the matrix has Good catch on the complex guys. Just point of information to other readers; very minor doc issues are corrected in #9746. |
comment:19
Replying to @kcrisman:
Okay, I think that these two things combine to make this happen, after reading this again. I still don't know if I like sparse and dense matrices looking so different. So the idea is that the little circle points indicate sparse, while the boxes indicate dense? I'm thinking of
Also, my favorite use case doesn't work yet, though to be fair it didn't work before, so this shouldn't hold things up (and is a currently open ticket). But just in case, is there a quick way to get this now? After all, one might want the first row to be labeled 1 sometimes!
I should be able to finish reviewing this later on today. |
comment:20
I fixed the issues you mentioned. I also changed the option name to Yes, the defaults may change slightly with the steps option. I don't know why I didn't put in those steps defaults before; they look better, and this will provide consistency to have the same steps options for different calls. Possibly it should have gone on another ticket, but I already had to consolidate things for the integer option. |
comment:21
I didn't fix the issues you mentioned in #9740 comment:19, though. |
comment:22
Replying to @kcrisman:
Yes; you can choose the marker used in sparse matrices. Aside from the fact that this is a fundamental difference in matplotlib, it does also make sense. In dense matrices, most entries are nonzero, so you color every pixel/square. In sparse matrices, most entries are zero, so you only put a marker where there is a nonzero.
Yes, definitely another ticket. |
comment:23
of course, your ticks example above does not label the first row 1; it would only put a tick on the second row (if it worked). You probably want to change the tick_formatter argument to relabel things. |
comment:24
Replying to @jasongrout:
That's okay, they are preexisting behavior and still similar, so can be discussed elsewhere. You beat me to realizing the rebase needed now in #4342. Luckily I could just roll that back... someday I'll use queues. |
comment:25
Okay, in general this is great! I love the live documentation for testing, by the way - don't know why I never thought of that before. Two things, which perhaps should still be addressed - what do you think? First, the error message with the Second, there are two instances of
in the documentation for I like that the error message for when I also just noticed that the doc for |
comment:26
Or in #9746?
After thinking about it, since the ticket says to wrap more mpl options, this should be addressed on this ticket. |
Reviewer: Karl-Dieter Crisman |
apply on top of previous patches |
comment:28
Attachment: 9740-review-fixes.patch.gz I updated the review-fixes patch to take care of the issues you brought up. I also polished two more references in the docs. |
comment:29
Thanks a ton - the only other thing I saw is fixed in #9746, so all is well, other than stuff above that can go in another ticket. Positive review. |
Merged: sage-4.6.alpha3 |
This patch:
CC: @rbeezer @kcrisman
Component: graphics
Author: Jason Grout
Reviewer: Karl-Dieter Crisman
Merged: sage-4.6.alpha3
Issue created by migration from https://trac.sagemath.org/ticket/9740
The text was updated successfully, but these errors were encountered: