Skip to content
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

Y-axis labels on matrix_plot are reversed. #18612

Closed
deinst opened this issue Jun 4, 2015 · 21 comments
Closed

Y-axis labels on matrix_plot are reversed. #18612

deinst opened this issue Jun 4, 2015 · 21 comments

Comments

@deinst
Copy link
Contributor

deinst commented Jun 4, 2015

This is a regression caused by the partial fix in #18463.

matrix_plot(identity_matrix(5))

has the y-axis labels ascending, while they should be descending.

CC: @kcrisman @strogdon @williamstein

Component: graphics

Author: David Einstein

Branch/Commit: 008ece0

Reviewer: Karl-Dieter Crisman

Issue created by migration from https://trac.sagemath.org/ticket/18612

@deinst deinst added this to the sage-6.8 milestone Jun 4, 2015
@deinst
Copy link
Contributor Author

deinst commented Jun 4, 2015

Incorrect image

@kcrisman
Copy link
Member

kcrisman commented Jun 5, 2015

comment:1

Attachment: tmp_ST550r.png

@kcrisman
Copy link
Member

comment:2
sage: p = 13; matrix_plot(matrix(p-1,[mod(a,p)^b for a in range(1,p) for b in srange(p)]),cmap='jet')
Launched png viewer for Graphics object consisting of 1 graphics primitive

Looks great, but y-axis labels reversed (known bug from #18463).

sage: p = 13; matrix_plot(matrix(p-1,[mod(a,p)^b for a in range(1,p) for b in srange(p)]),cmap='jet', origin='lower')
Launched png viewer for Graphics object consisting of 1 graphics primitive

Labels correct, but image upside-down.


Could we just ("just") use pyplot.yticks to get the vertical ticks and then immediately reverse their order? Or something like

sage: m.gca().get_yticks()
array([ -2.,   0.,   2.,   4.,   6.,   8.,  10.,  12.])
sage: m.gca().set_yticks(m.gca().get_yticks()[::-1])

I can't get this to quite work because I don't have the tkagg enabled for my Sage matplotlib, but inside of Sage something doing this should (hopefully) work.

http://stackoverflow.com/questions/9382664/python-matplotlib-imshow-custom-tickmarks

http://matplotlib.org/api/axes_api.html#matplotlib.axes.Axes.get_yticks

@deinst
Copy link
Contributor Author

deinst commented Jun 24, 2015

comment:3

I think that it is more complicated than that.

I know next to nothing about the Sage graphics system, please feel free to clarify any blatant falsehoods.

The MatrixPlot object is a GraphicsPrimitive and is responsible for drawing the image. The axes are drawn by the containing Graphics object which contains the MatrixPlot. There may be a member of Graphics that allows us to relabel the axes that we could call in matrix_plot, but I do not know what it would be.

The more I look at this, I think that the best short term solution would be to back out #18463 and put an abs in _limit_output_aspect_ratio. This is possibly wrong in terms of composed plots, but things would work correctly for the use cases that we have now. It would not be incorrect in the case that ymax>ymin, just somewhat wasteful.

Does there exist high level documentation of the Graphics subsytem somewhere? Something which describes how sums of plots are supposed to work, how to draw different axes for different plots in a single Graphics object would be nice.

@kcrisman
Copy link
Member

comment:5

Hmm, you may be right. Yes, composed plots will probably nearly always be wrong, but I'm not sure anyone anticipated combining "regular" plots with matrix plots or indeed even combining two matrix plots.

Given the many reports, we need a fix for #18463, and I would strongly prefer one that is less elegant but preserves current functionality. As Volker says elsewhere, the graphics code is convoluted enough, so this will not do much damage there.

@deinst
Copy link
Contributor Author

deinst commented Jun 25, 2015

@deinst
Copy link
Contributor Author

deinst commented Jun 25, 2015

Author: David Einstein

@deinst
Copy link
Contributor Author

deinst commented Jun 25, 2015

Commit: 05875d5

@deinst
Copy link
Contributor Author

deinst commented Jun 25, 2015

comment:7

Ok, I am at Juliacon and don't have a bunch of time (not enough to run the long tests). This is the proposed fix. It appears to work, but is at least philosophically ugly.

@kcrisman
Copy link
Member

comment:8

I think you may have put the wrong branch? It says "already merged". Thanks very much though, I will check it out today or tomorrow.

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jun 25, 2015

Changed commit from 05875d5 to 008ece0

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jun 25, 2015

Branch pushed to git repo; I updated commit sha1. New commits:

008ece0add abs to scaling of aspect ratio

@deinst
Copy link
Contributor Author

deinst commented Jun 25, 2015

comment:10

Doh! Sorry, I forgot to commit the change before pushing.

@kcrisman
Copy link
Member

comment:11

William, if you see this - would this solution suffice for SMC purposes as well?

Regarding ugly, #18463 comment:4 already points out that problem. I just think that we haven't really ever talked about adding matrix plots to each other or anything else in documentation, and it's best to fix that elsewhere - hopefully in a way that also fixes this problem 'correctly'.

Also, for my or other testing reference, do

sage: i = identity_matrix(10,sparse=True)
sage: matrix_plot(i)
sage: matrix_plot(i, aspect_ratio='automatic')

as an example that David mentioned in the previous ticket.

@kcrisman
Copy link
Member

comment:12
sage: i = identity_matrix(10,sparse=True)
sage: matrix_plot(i)

Oh, I remember now - that is just a difference in how we plotted sparse matrices, not related to all this stuff.

@kcrisman
Copy link
Member

comment:13

I'm happy with this, ugly or not.

Can you think of ANY way for us to doctest the graphic itself (perhaps the bounding box or other attribute) to ensure this doesn't happen again?

@kcrisman
Copy link
Member

Reviewer: Karl-Dieter Crisman

@kcrisman
Copy link
Member

comment:14

Oh wait, I forgot to make sure that this still makes things work in general, since it actually changes all graphics, not just matrix plot. But I'm happy on the matrix plot side; if anyone checks that this works for normal graphics (including ones with ymin>ymax etc.) then we are good to go.

Update: they seem to in spot checks. Running doctests.

@kcrisman
Copy link
Member

comment:15

Tests pass.

@kcrisman
Copy link
Member

comment:16

Okay, I can't find any problems here in spot checking other graphics types and using those keywords, as expected.

@vbraun
Copy link
Member

vbraun commented Jun 30, 2015

Changed branch from u/deinst/y_axis_labels_on_matrix_plot_are_reversed_ to 008ece0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants