sagemath / sage

Main repository of SageMath
https://www.sagemath.org
Other
1.37k stars 466 forks source link

Implement plots with logarithmic scale #4529

Closed 0d90674f-05eb-4b9d-9cb6-7d583bd8b339 closed 12 years ago

0d90674f-05eb-4b9d-9cb6-7d583bd8b339 commented 15 years ago

Attached is a patch which introduces log scale to Graphics() class.

Depends on #12974.

Apply


OLD DISCUSSION BELOW :)

Currently plot() has no option to use logarithmic scales.

One workaround is to use matplotlib directly, with its semilogy(), semilogx() and loglog() functions, but that wouldn't produce plots with the customisations implemented in sage. Another workaround is messing with the plot figure like:

import pylab
p=plot(x,marker='.')
f=pylab.figure()
f.gca().set_xscale('log')
p.save(figure=f)

But that creates two problems:

Also, this requires the user to know how to deal with figures, which is not directly exposed by sage.

There are some possibilities to fix that:

  1. Make plot() detect if the figure changes the scales and modify the adaptive algorithm and the axis codes accordingly
  2. Create a kwarg to tell plot() to implement the scale-change internally
  3. Create other functions to use loglog(), semilogx() and semilogy()
  4. Many (or all) of the above together, since they aren't mutually exclusive

From what I noticed, Mathematica implements the separate functions way, but it may be better to fix the issue in plot() itself and if the other functions are wanted, just make it so that they call plot() with the correct arguments

Depends on #12810 Depends on #12605 Depends on #12974

Component: graphics

Keywords: plot log scale

Author: Punarbasu Purkayastha, Karl-Dieter Crisman

Reviewer: Karl-Dieter Crisman, Punarbasu Purkayastha

Merged: sage-5.2.beta1

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

ppurka commented 12 years ago

Attachment: trac_4529-docs-and-funcs.2.patch.gz

ppurka commented 12 years ago

Attachment: trac_4529-typo_fixes-rebase.2.patch.gz

ppurka commented 12 years ago
comment:74

I noticed that the case when scale is a list wasn't handled for changing aspect ratio in the new code. It's a non-fatal case, but it is nice to make sure that user doesn't get warnings from mpl. Updated two of the patches. Changes can be seen here.

Patchbot apply: trac_4529-add-log-scale.patch trac_4529-single-tick.patch trac_4529-docs-and-funcs.2.patch trac_4529-more-doc.patch trac_4529-typo_fixes-rebase.2.patch trac_4529-final-fixes.patch

ppurka commented 12 years ago

Description changed:

--- 
+++ 
@@ -5,9 +5,9 @@
 Apply 
 * [attachment: trac_4529-add-log-scale.patch](https://github.com/sagemath/sage-prod/files/10642608/trac_4529-add-log-scale.patch.gz)
 * [attachment: trac_4529-single-tick.patch](https://github.com/sagemath/sage-prod/files/10642609/trac_4529-single-tick.patch.gz)
-* [attachment: trac_4529-docs-and-funcs.patch](https://github.com/sagemath/sage-prod/files/10642610/trac_4529-docs-and-funcs.patch.gz)
+* [attachment: trac_4529-docs-and-funcs.2.patch](https://github.com/sagemath/sage-prod/files/10642615/trac_4529-docs-and-funcs.2.patch.gz)
 * [attachment: trac_4529-more-doc.patch](https://github.com/sagemath/sage-prod/files/10642611/trac_4529-more-doc.patch.gz)
-* [attachment: trac_4529-typo_fixes-rebase.patch](https://github.com/sagemath/sage-prod/files/10642614/trac_4529-typo_fixes-rebase.patch.gz)
+* [attachment: trac_4529-typo_fixes-rebase.2.patch](https://github.com/sagemath/sage-prod/files/10642616/trac_4529-typo_fixes-rebase.2.patch.gz)
 * [attachment: trac_4529-final-fixes.patch](https://github.com/sagemath/sage-prod/files/10642613/trac_4529-final-fixes.patch.gz)

 Alternate instructions:
@@ -24,9 +24,9 @@
 ../../sage -hg qimport -P https://github.com/sagemath/sage-prod/files/10655558/trac_12974-whitespace-rebased.patch.gz
 ../../sage -hg qimport -P https://github.com/sagemath/sage-prod/files/10642608/trac_4529-add-log-scale.patch.gz
 ../../sage -hg qimport -P https://github.com/sagemath/sage-prod/files/10642609/trac_4529-single-tick.patch.gz
-../../sage -hg qimport -P https://github.com/sagemath/sage-prod/files/10642610/trac_4529-docs-and-funcs.patch.gz
+../../sage -hg qimport -P https://github.com/sagemath/sage-prod/files/10642615/trac_4529-docs-and-funcs.2.patch.gz
 ../../sage -hg qimport -P https://github.com/sagemath/sage-prod/files/10642611/trac_4529-more-doc.patch.gz
-../../sage -hg qimport -P https://github.com/sagemath/sage-prod/files/10642614/trac_4529-typo_fixes-rebase.patch.gz
+../../sage -hg qimport -P https://github.com/sagemath/sage-prod/files/10642616/trac_4529-typo_fixes-rebase.2.patch.gz
 ../../sage -hg qimport -P https://github.com/sagemath/sage-prod/files/10642613/trac_4529-final-fixes.patch.gz
 ../../sage -b
kcrisman commented 12 years ago
comment:75

Okay by me as long as it all still applies, as it appears you have been very careful to ensure! You really do find some good corner cases!

kcrisman commented 12 years ago
comment:78

I'll try to rebase #12974 this morning.

jdemeyer commented 12 years ago
comment:79

Note that #12974 needs work though...

kcrisman commented 12 years ago
comment:80

Note that #12974 needs work though...

Yes, I saw that. It looks like they are all the result of just one name-mangling change or something, though, so hopefully not a problem.

kcrisman commented 12 years ago
comment:81

Okay, #12974 seems to be all set, so one would just have to check that this still applied on top of that.

kcrisman commented 12 years ago
comment:82

Yuck. Lots of places it doesn't apply correctly. I'll try to take care of this now.

kcrisman commented 12 years ago
comment:83

Every single conflict was due to whitespace (and hence probably fallout from #12974's extra patch. Grr. Patches coming up.

jasongrout commented 12 years ago
comment:84

Wasn't the whitespace patch from #12974 removed? Why are there still conflicts?

kcrisman commented 12 years ago
comment:85

Wasn't the whitespace patch from #12974 removed? Why are there still conflicts?

It was removed. But these patches are all based on the 'old' #12974. There would not have been conflicts if we had kept that patch.

Anyway, I just finished, so hold on a sec. It would be good for someone to look at things to make sure I did the rebasing right.

kcrisman commented 12 years ago

Attachment: trac_4529-patch1.patch.gz

Attachment: trac_4529-patch2.patch.gz

kcrisman commented 12 years ago

Attachment: trac_4529-patch3.patch.gz

Attachment: trac_4529-patch5.patch.gz

kcrisman commented 12 years ago

Attachment: trac_4529-patch6.patch.gz

kcrisman commented 12 years ago
comment:86

Sorry for all the patches, but I was trying to make sure things looked the same. These are the same six patches, just in numerical number - didn't want to add more rebase suffixes.

Apply

kcrisman commented 12 years ago

Description changed:

--- 
+++ 
@@ -3,33 +3,12 @@
 Depends on #12974.

 Apply 
-* [attachment: trac_4529-add-log-scale.patch](https://github.com/sagemath/sage-prod/files/10642608/trac_4529-add-log-scale.patch.gz)
-* [attachment: trac_4529-single-tick.patch](https://github.com/sagemath/sage-prod/files/10642609/trac_4529-single-tick.patch.gz)
-* [attachment: trac_4529-docs-and-funcs.2.patch](https://github.com/sagemath/sage-prod/files/10642615/trac_4529-docs-and-funcs.2.patch.gz)
-* [attachment: trac_4529-more-doc.patch](https://github.com/sagemath/sage-prod/files/10642611/trac_4529-more-doc.patch.gz)
-* [attachment: trac_4529-typo_fixes-rebase.2.patch](https://github.com/sagemath/sage-prod/files/10642616/trac_4529-typo_fixes-rebase.2.patch.gz)
-* [attachment: trac_4529-final-fixes.patch](https://github.com/sagemath/sage-prod/files/10642613/trac_4529-final-fixes.patch.gz)
-
-Alternate instructions:
-
-Apply the following patches in the specified order. `SAGE_ROOT` is the directory where the sage installation is present.
-
-```
-cd SAGE_ROOT/devel/sage
-../../sage -hg qimport -P https://github.com/sagemath/sage-prod/files/10655304/trac_12810-rebased.patch.gz
-../../sage -hg qimport -P https://github.com/sagemath/sage-prod/files/10654997/trac_12605-circle-color-graphplot-doc-rebased.patch.gz
-../../sage -hg qimport -P https://github.com/sagemath/sage-prod/files/10655560/trac_12974-fix_graphics_attributes-rebase.2.patch.gz
-../../sage -hg qimport -P https://github.com/sagemath/sage-prod/files/10655555/trac_12974-refactor.patch.gz
-../../sage -hg qimport -P https://github.com/sagemath/sage-prod/files/10655556/trac_12974-reorder_some_arguments.patch.gz
-../../sage -hg qimport -P https://github.com/sagemath/sage-prod/files/10655558/trac_12974-whitespace-rebased.patch.gz
-../../sage -hg qimport -P https://github.com/sagemath/sage-prod/files/10642608/trac_4529-add-log-scale.patch.gz
-../../sage -hg qimport -P https://github.com/sagemath/sage-prod/files/10642609/trac_4529-single-tick.patch.gz
-../../sage -hg qimport -P https://github.com/sagemath/sage-prod/files/10642615/trac_4529-docs-and-funcs.2.patch.gz
-../../sage -hg qimport -P https://github.com/sagemath/sage-prod/files/10642611/trac_4529-more-doc.patch.gz
-../../sage -hg qimport -P https://github.com/sagemath/sage-prod/files/10642616/trac_4529-typo_fixes-rebase.2.patch.gz
-../../sage -hg qimport -P https://github.com/sagemath/sage-prod/files/10642613/trac_4529-final-fixes.patch.gz
-../../sage -b
-```
+* [attachment: trac_4529-patch1.patch](https://github.com/sagemath/sage-prod/files/10642617/trac_4529-patch1.patch.gz)
+* [attachment: trac_4529-patch2.patch](https://github.com/sagemath/sage-prod/files/10642618/trac_4529-patch2.patch.gz)
+* [attachment: trac_4529-patch3.patch](https://github.com/sagemath/sage-prod/files/10642619/trac_4529-patch3.patch.gz)
+* [attachment: trac_4529-patch4.patch](https://github.com/sagemath/sage-prod/files/10642622/trac_4529-patch4.patch.gz)
+* [attachment: trac_4529-patch5.patch](https://github.com/sagemath/sage-prod/files/10642620/trac_4529-patch5.patch.gz)
+* [attachment: trac_4529-patch6.patch](https://github.com/sagemath/sage-prod/files/10642621/trac_4529-patch6.patch.gz)

 ---
 **OLD DISCUSSION BELOW :)**
kcrisman commented 12 years ago
comment:87

Plots seem fine still.

With respect to one minor issue - this is nothing to do with positive review, but a question for ppurka.

Compare

plot(x,(x,-1,1),xmin=1,xmax=-1)
plot(x,(x,-1,1)).show(xmin=1,xmax=-1)

with the patches (or even just first patch). I would think they should be the same (i.e., like the second one, as commented in the first patch).

ppurka commented 12 years ago
comment:88

Hello, sorry for not being able to participate. Currntly posting from an airport kiosk. I thought they should be the same. I will have to check if the code is only triggered from matplotlib, or if the points are sorted before the render_to_subplot.

ppurka commented 12 years ago
comment:89

By the way many thanks to you (kcrisman), jason and jeroen for doing the rebasing :)

kcrisman commented 12 years ago
comment:90

Hello, sorry for not being able to participate. Currntly posting from an airport kiosk. I thought they should be the same. I will have to check if the code is only triggered from matplotlib, or if the points are sorted before the render_to_subplot.

I wouldn't be surprised if they were.

Anyway, when you figure it out, open a ticket :) Have a great trip, wherever you go.

jdemeyer commented 12 years ago
comment:91

Replying to @kcrisman:

Sorry for all the patches, but I was trying to make sure things looked the same. These are the same six patches, just in numerical number

Awesome!

jdemeyer commented 12 years ago
comment:93

attachment: trac_4529-patch4.patch needs a proper commit message.

kcrisman commented 12 years ago
comment:94

attachment: trac_4529-patch4.patch needs a proper commit message.

Huh, that happened the last time too. Sorry, I don't know how I missed that. Coming up.

kcrisman commented 12 years ago
comment:95

Attachment: trac_4529-patch4.patch.gz

kcrisman commented 12 years ago
comment:96

Ok, should be all set.

jdemeyer commented 12 years ago

Merged: sage-5.2.beta1

kcrisman commented 12 years ago
comment:98

Replying to @kcrisman:

I found my "lost" patch. phew

Good thing!

I've opened https://github.com/matplotlib/matplotlib/issues/909 for the mpl issue. Hopefully we'll hear something eventually.

ppurka:

Did we ever open a ticket for fixing this? Anyway, it's been resolved in this mpl pull request, apparently. I think that we put in a comment about how this doesn't (yet) work, so there would be something to do now that this has been done.