[sage-devel] Re: Display of scale multiplier in scientific notation (the e notation for powers of ten) is missing for plots starting with 0

2022-08-01 Thread kcrisman
This looks likely, thanks!  The next step for you (and all of us) would be 
as follows:

1) Neither of these codes are so long that you couldn't put them as 
formatted text in comments on the relevant ticket.  Use {{{ code }}} to 
format them.

2) If you could (on the ticket) attach or link to images of the 
before/after, that would be very helpful.  Particularly the `use_mathtext` 
option being different would need discussion and comparison.

Thanks! I hope others look at this issue too, as I may not have margin for 
a full review at this time.

On Friday, July 29, 2022 at 4:31:02 PM UTC-4 niran...@gmail.com wrote:

> Wait, i just solved it!
>  It is not the issue with matplotlib but with the construction of 
> SelectiveFormatter. 
> This formatter construction is incomplete. I have created two new 
> customized ScalarFormatters (default formatters used by matplotlib), the 
> second one would be a good new addition to sage along with the first one. 
> We can have both. I have worked out same situation but in native python 
> with matplotlib. Only thing is to adapt it to sage. It won't be hard to do 
> that, just need slight adjustments. Please look into the attached two 
> example python files.
>
> Inspired from:
> https://stackoverflow.com/questions/11244514/modify-tick-label-text
> <-- Discusses similar issue (see second answer from last)
>
> https://stackoverflow.com/questions/63475934/skipping-certain-values-in-python-with-matplotlib
>
> https://github.com/matplotlib/matplotlib/blob/4f5cacfde9024076d9ab0cb6ad1c9a7cf352d5f9/lib/matplotlib/ticker.py
>
>
> On Saturday, July 30, 2022 at 12:05:24 AM UTC+5:30 kcrisman wrote:
>
>> Time being solution would be to drop use of  SelectiveFormatter to get 
>>> rid of 0 tick label if the axes cross. Let the origin be visible for some 
>>> time.
>>>
>>
>> My guess is that this would not be seen as a great fix, but let's put 
>> images and other followup on the ticket.
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sage-devel/4dae16a5-3024-46de-bf86-1cd5a233858fn%40googlegroups.com.


[sage-devel] Re: Display of scale multiplier in scientific notation (the e notation for powers of ten) is missing for plots starting with 0

2022-07-29 Thread Niranjana K M
Wait, i just solved it!
 It is not the issue with matplotlib but with the construction of 
SelectiveFormatter. 
This formatter construction is incomplete. I have created two new 
customized ScalarFormatters (default formatters used by matplotlib), the 
second one would be a good new addition to sage along with the first one. 
We can have both. I have worked out same situation but in native python 
with matplotlib. Only thing is to adapt it to sage. It won't be hard to do 
that, just need slight adjustments. Please look into the attached two 
example python files.

Inspired from:
https://stackoverflow.com/questions/11244514/modify-tick-label-text<-- 
Discusses similar issue (see second answer from last)
https://stackoverflow.com/questions/63475934/skipping-certain-values-in-python-with-matplotlib
https://github.com/matplotlib/matplotlib/blob/4f5cacfde9024076d9ab0cb6ad1c9a7cf352d5f9/lib/matplotlib/ticker.py


On Saturday, July 30, 2022 at 12:05:24 AM UTC+5:30 kcrisman wrote:

> Time being solution would be to drop use of  SelectiveFormatter to get 
>> rid of 0 tick label if the axes cross. Let the origin be visible for some 
>> time.
>>
>
> My guess is that this would not be seen as a great fix, but let's put 
> images and other followup on the ticket.
>

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sage-devel/3ccaa889-7548-4756-8024-2baa99dce5b6n%40googlegroups.com.
#!/usr/bin/python

import matplotlib
import matplotlib.pyplot as plt
import numpy as np

from matplotlib import rcParams
rcParams['axes.formatter.use_mathtext'] = True

class CustomScalarFormatter(matplotlib.ticker.ScalarFormatter):
def __init__(self, useOffset=None, useMathText=None, useLocale=None, skip_values=[]):
super().__init__(useOffset=None, useMathText=None, useLocale=None)
self.skip_values = skip_values

def __call__(self, x, pos=None):
"""
Return the format for tick value *x* at position *pos*.
"""
if len(self.locs) == 0:
return ''
#elif x == 0:
#return ''
elif x in self.skip_values:
return ''
else:
xp = (x - self.offset) / (10. ** self.orderOfMagnitude)
if abs(xp) < 1e-8:
xp = 0
return self._format_maybe_minus_and_locale(self.format, xp)

z = np.linspace(-5000, 5000, 100)

fig, ax = plt.subplots()
ax.plot(z,z**2)


xmajorformatter = CustomScalarFormatter(skip_values=[2000,0])
ymajorformatter = CustomScalarFormatter(skip_values=[1E7,0])
ax.xaxis.set_major_formatter(xmajorformatter)
ax.yaxis.set_major_formatter(ymajorformatter)

plt.show()#!/usr/bin/python

import matplotlib
import matplotlib.pyplot as plt
import numpy as np

from matplotlib import rcParams
rcParams['axes.formatter.use_mathtext'] = True

class CustomScalarFormatter(matplotlib.ticker.ScalarFormatter):
def __init__(self, useOffset=None, useMathText=None, useLocale=None, replace_values=[]):
super().__init__(useOffset=None, useMathText=None, useLocale=None)
self.replace_values = replace_values

def __call__(self, x, pos=None):
"""
Return the format for tick value *x* at position *pos*.
"""
if len(self.locs) == 0:
return ''
#elif x == 0:
#return ''
elif x in self.replace_values[0]:
idx = self.replace_values[0].index(x)
return str(self.replace_values[1][idx])
else:
xp = (x - self.offset) / (10. ** self.orderOfMagnitude)
if abs(xp) < 1e-8:
xp = 0
return self._format_maybe_minus_and_locale(self.format, xp)



z = np.linspace(0, 5000, 100)
fig, ax = plt.subplots()
ax.plot(z,z**2)


xmajorformatter = CustomScalarFormatter(replace_values=([2000,0],['$x_0$','']))
ymajorformatter = CustomScalarFormatter(replace_values=([1E7,0],['$y_0$','']))
ax.xaxis.set_major_formatter(xmajorformatter)
ax.yaxis.set_major_formatter(ymajorformatter)

plt.show()

[sage-devel] Re: Display of scale multiplier in scientific notation (the e notation for powers of ten) is missing for plots starting with 0

2022-07-29 Thread kcrisman


> Time being solution would be to drop use of  SelectiveFormatter to get 
> rid of 0 tick label if the axes cross. Let the origin be visible for some 
> time.
>

My guess is that this would not be seen as a great fix, but let's put 
images and other followup on the ticket.

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sage-devel/40e9f372-8e0a-4887-a6b0-ae984de05a19n%40googlegroups.com.


[sage-devel] Re: Display of scale multiplier in scientific notation (the e notation for powers of ten) is missing for plots starting with 0

2022-07-28 Thread Niranjana K M
@kcrisman

Thanks for the continued conversation.  I hope it was clear that "we would 
> be grateful" implied that there was no compulsion on your part, as well as 
> on the part of any other contributor.


There is no such compulsion, indeed I like working with SAGE. My reply 
about my other ticket was just with light heart to make you to look into my 
first ticket.
 

> However, I couldn't replicate the example you gave - among other thing, 
> show(p) gave me something that wasn't plottable (I had to use savefig etc. 
> on the figure itself).
>

savefig was the one given in doc and the right one. I just tried in 
shortcut and somehow the plot appeared in my notebook with a error string 
[홻횒횗횎ퟸ홳(⎯회횑횒횕획ퟶ)]
 

>  Also, what is your modified version trying to show - the missing part, or 
> a potential solution?  Thanks!
>

First we have to try natively matplotlib formatter to have similar 
selective formatting and confirm whether it is a matplotlib issue which is 
to be reported to upstream.
Then try to do something similar to
ax.xaxis.get_major_formatter().set_scientific(True)
ax.yaxis.get_major_formatter().set_scientific(True)
to re-enable scientific notation for axis.

I have to first study matplotlib formatter.

Also I noticed that,
*sage:* plot(x^2,(x,100,5000), tick_formatter="latex")
altogether dropped formatting in scientific notation and instead started 
printing like 2500.0. But typeset="latex"
*sage:* plot(x^2,(x,100,5000), typeset="latex")
does retain scientific notation

It may be clear from these that any tweaking with ticks is disturbing setting 
up of scientific notation. We have to explore whether there is any way to 
reintroduce scientific notation formatting as well.

Time being solution would be to drop use of  SelectiveFormatter to get rid 
of 0 tick label if the axes cross. Let the origin be visible for some time.

With regards
Niranjana

> ​

>>>

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sage-devel/4a71aae7-fccb-4660-8b3d-4b9cd005ec19n%40googlegroups.com.


[sage-devel] Re: Display of scale multiplier in scientific notation (the e notation for powers of ten) is missing for plots starting with 0

2022-07-28 Thread kcrisman
This is now https://trac.sagemath.org/ticket/34233

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sage-devel/03391f57-609e-492b-8a78-1fa1c6fdef0cn%40googlegroups.com.


[sage-devel] Re: Display of scale multiplier in scientific notation (the e notation for powers of ten) is missing for plots starting with 0

2022-07-28 Thread kcrisman
Thanks for the continued conversation.  I hope it was clear that "we would 
be grateful" implied that there was no compulsion on your part, as well as 
on the part of any other contributor.

I did notice the mathtext option, but since our previous version had used 
the e notation, changing that would be a separate ticket, and probably need 
some discussion.

I found it ! The problem is  in use of  SelectiveFormatter to get rid of 0 
> tick label if the axes cross. Commenting out lines
>

Great! That is half the battle, good detective work.. 

However, I couldn't replicate the example you gave - among other thing, 
show(p) gave me something that wasn't plottable (I had to use savefig etc. 
on the figure itself).  Also, what is your modified version trying to show 
- the missing part, or a potential solution?  Thanks!
 

>
> https://github.com/sagemath/sage/blob/develop/src/sage/plot/graphics.py#L2983
> to
>
> https://github.com/sagemath/sage/blob/develop/src/sage/plot/graphics.py#L2986
> from sage.plot.plot import SelectiveFormatter
> subplot.yaxis.set_major_formatter(SelectiveFormatter(
> subplot.yaxis.get_major_formatter(), skip_values=[0]))
> subplot.xaxis.set_major_formatter(SelectiveFormatter(
> subplot.xaxis.get_major_formatter(), skip_values=[0]))
>
> will bring back the scaling factor in scientific notation. But on the 
> downside it will print the origin 0.
>
> SelectiveFormatter use itself has this issue. A modified version of usage 
> example of SelectiveFormatter in Sage reference >> 2D Plotting
>
> from sage.plot.plot import SelectiveFormatter
> import matplotlib.pyplot as plt
> import numpy
>
> fig=plt.figure()
> ax=fig.add_subplot(111)
> t = numpy.arange(1000, 1010, 100)
> s = t
> p = ax.plot(t, s)
>
> formatter=SelectiveFormatter(ax.xaxis.get_major_formatter(),skip_values=[0,1])
>
> formatter=SelectiveFormatter(ax.yaxis.get_major_formatter(),skip_values=[0,1])
> ax.xaxis.set_major_formatter(formatter)
> ax.yaxis.set_major_formatter(formatter)
>
> show(p)
>
>>
>> ​
>>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sage-devel/4f7359fd-3b14-4f03-9cd6-0f953d8c5567n%40googlegroups.com.


[sage-devel] Re: Display of scale multiplier in scientific notation (the e notation for powers of ten) is missing for plots starting with 0

2022-07-28 Thread Niranjana K M
I found it ! The problem is  in use of  SelectiveFormatter to get rid of 0 
tick label if the axes cross. Commenting out lines

https://github.com/sagemath/sage/blob/develop/src/sage/plot/graphics.py#L2983
to
https://github.com/sagemath/sage/blob/develop/src/sage/plot/graphics.py#L2986
from sage.plot.plot import SelectiveFormatter
subplot.yaxis.set_major_formatter(SelectiveFormatter(
subplot.yaxis.get_major_formatter(), skip_values=[0]))
subplot.xaxis.set_major_formatter(SelectiveFormatter(
subplot.xaxis.get_major_formatter(), skip_values=[0]))

will bring back the scaling factor in scientific notation. But on the 
downside it will print the origin 0.

SelectiveFormatter use itself has this issue. A modified version of usage 
example of SelectiveFormatter in Sage reference >> 2D Plotting

from sage.plot.plot import SelectiveFormatter
import matplotlib.pyplot as plt
import numpy

fig=plt.figure()
ax=fig.add_subplot(111)
t = numpy.arange(1000, 1010, 100)
s = t
p = ax.plot(t, s)
formatter=SelectiveFormatter(ax.xaxis.get_major_formatter(),skip_values=[0,1])
formatter=SelectiveFormatter(ax.yaxis.get_major_formatter(),skip_values=[0,1])
ax.xaxis.set_major_formatter(formatter)
ax.yaxis.set_major_formatter(formatter)

show(p)

Any idea to fix it?

On Thursday, July 28, 2022 at 3:25:41 AM UTC+5:30 Niranjana K M wrote:

> Regarding axes Formatter, inserting
> rcParams['axes.formatter.use_mathtext'] = True
> just after
> from matplotlib import rcParams 
> in  graphics.py  makes the scientific notation to be typeset as  x 10^7 
> (for example). This looks nicer than 1e7. See the figure. Though it does 
> not solve the current problem, aesthetically it looks nice whenever the 
> scaling is displayed.
>
> [image: index.png]
>
> On Thursday, July 28, 2022 at 1:45:18 AM UTC+5:30 emanuel.c...@gmail.com 
> wrote:
>
>> Le mercredi 27 juillet 2022 à 16:53:39 UTC+2, niran…@gmail.com a écrit :
>>
>> Dear Kcrisman,
>>> I will look into it *if* you promise me to *review* and *close* my 
>>> another ticket   https://trac.sagemath.org/ticket/34038
>>> based on the thread   
>>> https://groups.google.com/g/sage-devel/c/tMH1RZNyC9s/m/DRwexGpzAwAJ
>>>
>> This ticket contains suggestion, is marked needs_review, but proposes no 
>> branch to review. Could you propose a patch implementing your suggestions ? 
>> The Developer’s guide 
>>  will guide you 
>> on the road to proposing such a patch as a branch of the Sage source git 
>> tree…
>>
>>  
>>>
>>> With regards
>>> Niranjana
>>>
>>> On Wednesday, July 27, 2022 at 7:05:51 PM UTC+5:30 kcrisman wrote:
>>>
 This is a good question, and one that has been around for a while in 
 some form, unfortunately; see https://trac.sagemath.org/ticket/7964 
 for a related ticket.   See https://trac.sagemath.org/ticket/30983 for 
 a ticket that complains instead about something else but which is closely 
 related.

 We would be grateful for any additional insight you might provide. 
  Here are some pieces of info about where we use matplotlib that you might 
 find useful in that regard.

 We use some specific matplotlib ticker and formatter options which 
 don't always play well here.  See 
 https://github.com/sagemath/sage/blob/develop/src/sage/plot/graphics.py#L2326
  
 for _matplotlib_tick_formatter in sage/plot/graphics.py

 In particular, note that, under ordinary circumstances,

 y_locator = MaxNLocator(**locator_options)
 y_formatter = ScalarFormatter()

 That is very close to the defaults for matplotlib, but maybe we are 
 using things in an antiquated way.  See e.g. 
 https://matplotlib.org/stable/api/ticker_api.html#matplotlib.ticker.ScalarFormatter
  

 On the other hand, if (as I suspect) that isn't the root issue, it 
 probably is in the save method (
 https://github.com/sagemath/sage/blob/develop/src/sage/plot/graphics.py#L3198).
  
  My first thought was that somehow fig_tight played a role, but 

 sage: plot(x^2,(x,0,5000),fig_tight=False)

 doesn't seem to be any different than the one you pointed out.  Another 
 possibility is tight_layout (
 https://matplotlib.org/stable/api/tight_layout_api.html) which we do 
 use, but which a little experimentation doesn't seem to indicate is the 
 problem either.
 On Tuesday, July 26, 2022 at 5:15:11 AM UTC-4 niran...@gmail.com wrote:

> Dear all,
> "2D plotting" doc says,
> "Another thing to be aware of with axis labeling is that when the 
> labels have quite different orders of magnitude or are very large, 
> scientific notation (the e  notation for powers of ten) is used."
>
> But display of this multiplier power for the scaled y-axis is missing 
> if the plot starts with x=0 or at 

[sage-devel] Re: Display of scale multiplier in scientific notation (the e notation for powers of ten) is missing for plots starting with 0

2022-07-27 Thread Niranjana K M
Regarding axes Formatter, inserting
rcParams['axes.formatter.use_mathtext'] = True
just after
from matplotlib import rcParams 
in  graphics.py  makes the scientific notation to be typeset as  x 10^7 
(for example). This looks nicer than 1e7. See the figure. Though it does 
not solve the current problem, aesthetically it looks nice whenever the 
scaling is displayed.

[image: index.png]

On Thursday, July 28, 2022 at 1:45:18 AM UTC+5:30 emanuel.c...@gmail.com 
wrote:

> Le mercredi 27 juillet 2022 à 16:53:39 UTC+2, niran…@gmail.com a écrit :
>
> Dear Kcrisman,
>> I will look into it *if* you promise me to *review* and *close* my 
>> another ticket   https://trac.sagemath.org/ticket/34038
>> based on the thread   
>> https://groups.google.com/g/sage-devel/c/tMH1RZNyC9s/m/DRwexGpzAwAJ
>>
> This ticket contains suggestion, is marked needs_review, but proposes no 
> branch to review. Could you propose a patch implementing your suggestions ? 
> The Developer’s guide 
>  will guide you on 
> the road to proposing such a patch as a branch of the Sage source git 
> tree…
>
>  
>>
>> With regards
>> Niranjana
>>
>> On Wednesday, July 27, 2022 at 7:05:51 PM UTC+5:30 kcrisman wrote:
>>
>>> This is a good question, and one that has been around for a while in 
>>> some form, unfortunately; see https://trac.sagemath.org/ticket/7964 for 
>>> a related ticket.   See https://trac.sagemath.org/ticket/30983 for a 
>>> ticket that complains instead about something else but which is closely 
>>> related.
>>>
>>> We would be grateful for any additional insight you might provide.  Here 
>>> are some pieces of info about where we use matplotlib that you might find 
>>> useful in that regard.
>>>
>>> We use some specific matplotlib ticker and formatter options which don't 
>>> always play well here.  See 
>>> https://github.com/sagemath/sage/blob/develop/src/sage/plot/graphics.py#L2326
>>>  
>>> for _matplotlib_tick_formatter in sage/plot/graphics.py
>>>
>>> In particular, note that, under ordinary circumstances,
>>>
>>> y_locator = MaxNLocator(**locator_options)
>>> y_formatter = ScalarFormatter()
>>>
>>> That is very close to the defaults for matplotlib, but maybe we are 
>>> using things in an antiquated way.  See e.g. 
>>> https://matplotlib.org/stable/api/ticker_api.html#matplotlib.ticker.ScalarFormatter
>>>  
>>>
>>> On the other hand, if (as I suspect) that isn't the root issue, it 
>>> probably is in the save method (
>>> https://github.com/sagemath/sage/blob/develop/src/sage/plot/graphics.py#L3198).
>>>  
>>>  My first thought was that somehow fig_tight played a role, but 
>>>
>>> sage: plot(x^2,(x,0,5000),fig_tight=False)
>>>
>>> doesn't seem to be any different than the one you pointed out.  Another 
>>> possibility is tight_layout (
>>> https://matplotlib.org/stable/api/tight_layout_api.html) which we do 
>>> use, but which a little experimentation doesn't seem to indicate is the 
>>> problem either.
>>> On Tuesday, July 26, 2022 at 5:15:11 AM UTC-4 niran...@gmail.com wrote:
>>>
 Dear all,
 "2D plotting" doc says,
 "Another thing to be aware of with axis labeling is that when the 
 labels have quite different orders of magnitude or are very large, 
 scientific notation (the e  notation for powers of ten) is used."

 But display of this multiplier power for the scaled y-axis is missing 
 if the plot starts with x=0 or at most will be missing till the x-axis 
 detaches from the origin. Following examples illustrates it,

 *sage:*  plot(x^2,(x,0,5000))  # missing display of 1e7 above y-axis
 *sage:*  plot(x^2,(x,50,5000))  # missing display of 1e7 above y-axis
 *sage:*  plot(x^2,(x,100,5000))  # display of 1e7 above y-axis is 
 visible

 On the other side matplotlib natively always displays the scale 
 multiplier (if any) whenever numbers are large. For example:

 *sage:*  import matplotlib.pyplot as plt
 *sage:*  import numpy as np
 *sage:*  z = np.linspace(0, 5000, 100)
 *sage:*  plt.plot(z, z**2)
 *sage:*  plt.show()

 My other plots involved electric field calculations which had 
 magnitudes around 1/epsilon_0 which is 1/(8.85E-12) =~ 10^11. For those 
 plots starting with x=0 the display of multiplier used for y-axis were 
 missing.

 With regards
 Niranjana

>>> ​
>

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sage-devel/a83484f1-796b-4872-986a-8ac2541db4b3n%40googlegroups.com.


[sage-devel] Re: Display of scale multiplier in scientific notation (the e notation for powers of ten) is missing for plots starting with 0

2022-07-27 Thread Niranjana K M
Very sorry. I am new to git and that was my first trac ticket ever. If 
somebody can take it up patching i would be happy.
On Thursday, July 28, 2022 at 1:45:18 AM UTC+5:30 emanuel.c...@gmail.com 
wrote:

> Le mercredi 27 juillet 2022 à 16:53:39 UTC+2, niran…@gmail.com a écrit :
>
> Dear Kcrisman,
>> I will look into it *if* you promise me to *review* and *close* my 
>> another ticket   https://trac.sagemath.org/ticket/34038
>> based on the thread   
>> https://groups.google.com/g/sage-devel/c/tMH1RZNyC9s/m/DRwexGpzAwAJ
>>
> This ticket contains suggestion, is marked needs_review, but proposes no 
> branch to review. Could you propose a patch implementing your suggestions ? 
> The Developer’s guide 
>  will guide you on 
> the road to proposing such a patch as a branch of the Sage source git 
> tree…
>
>  
>>
>> With regards
>> Niranjana
>>
>> On Wednesday, July 27, 2022 at 7:05:51 PM UTC+5:30 kcrisman wrote:
>>
>>> This is a good question, and one that has been around for a while in 
>>> some form, unfortunately; see https://trac.sagemath.org/ticket/7964 for 
>>> a related ticket.   See https://trac.sagemath.org/ticket/30983 for a 
>>> ticket that complains instead about something else but which is closely 
>>> related.
>>>
>>> We would be grateful for any additional insight you might provide.  Here 
>>> are some pieces of info about where we use matplotlib that you might find 
>>> useful in that regard.
>>>
>>> We use some specific matplotlib ticker and formatter options which don't 
>>> always play well here.  See 
>>> https://github.com/sagemath/sage/blob/develop/src/sage/plot/graphics.py#L2326
>>>  
>>> for _matplotlib_tick_formatter in sage/plot/graphics.py
>>>
>>> In particular, note that, under ordinary circumstances,
>>>
>>> y_locator = MaxNLocator(**locator_options)
>>> y_formatter = ScalarFormatter()
>>>
>>> That is very close to the defaults for matplotlib, but maybe we are 
>>> using things in an antiquated way.  See e.g. 
>>> https://matplotlib.org/stable/api/ticker_api.html#matplotlib.ticker.ScalarFormatter
>>>  
>>>
>>> On the other hand, if (as I suspect) that isn't the root issue, it 
>>> probably is in the save method (
>>> https://github.com/sagemath/sage/blob/develop/src/sage/plot/graphics.py#L3198).
>>>  
>>>  My first thought was that somehow fig_tight played a role, but 
>>>
>>> sage: plot(x^2,(x,0,5000),fig_tight=False)
>>>
>>> doesn't seem to be any different than the one you pointed out.  Another 
>>> possibility is tight_layout (
>>> https://matplotlib.org/stable/api/tight_layout_api.html) which we do 
>>> use, but which a little experimentation doesn't seem to indicate is the 
>>> problem either.
>>> On Tuesday, July 26, 2022 at 5:15:11 AM UTC-4 niran...@gmail.com wrote:
>>>
 Dear all,
 "2D plotting" doc says,
 "Another thing to be aware of with axis labeling is that when the 
 labels have quite different orders of magnitude or are very large, 
 scientific notation (the e  notation for powers of ten) is used."

 But display of this multiplier power for the scaled y-axis is missing 
 if the plot starts with x=0 or at most will be missing till the x-axis 
 detaches from the origin. Following examples illustrates it,

 *sage:*  plot(x^2,(x,0,5000))  # missing display of 1e7 above y-axis
 *sage:*  plot(x^2,(x,50,5000))  # missing display of 1e7 above y-axis
 *sage:*  plot(x^2,(x,100,5000))  # display of 1e7 above y-axis is 
 visible

 On the other side matplotlib natively always displays the scale 
 multiplier (if any) whenever numbers are large. For example:

 *sage:*  import matplotlib.pyplot as plt
 *sage:*  import numpy as np
 *sage:*  z = np.linspace(0, 5000, 100)
 *sage:*  plt.plot(z, z**2)
 *sage:*  plt.show()

 My other plots involved electric field calculations which had 
 magnitudes around 1/epsilon_0 which is 1/(8.85E-12) =~ 10^11. For those 
 plots starting with x=0 the display of multiplier used for y-axis were 
 missing.

 With regards
 Niranjana

>>> ​
>

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sage-devel/aaf229fa-b702-4a91-9208-66e9a4ca9d91n%40googlegroups.com.


[sage-devel] Re: Display of scale multiplier in scientific notation (the e notation for powers of ten) is missing for plots starting with 0

2022-07-27 Thread Emmanuel Charpentier


Le mercredi 27 juillet 2022 à 16:53:39 UTC+2, niran…@gmail.com a écrit :

Dear Kcrisman,
> I will look into it *if* you promise me to *review* and *close* my 
> another ticket   https://trac.sagemath.org/ticket/34038
> based on the thread   
> https://groups.google.com/g/sage-devel/c/tMH1RZNyC9s/m/DRwexGpzAwAJ
>
This ticket contains suggestion, is marked needs_review, but proposes no 
branch to review. Could you propose a patch implementing your suggestions ? 
The Developer’s guide 
 will guide you on 
the road to proposing such a patch as a branch of the Sage source git tree…

 
>
> With regards
> Niranjana
>
> On Wednesday, July 27, 2022 at 7:05:51 PM UTC+5:30 kcrisman wrote:
>
>> This is a good question, and one that has been around for a while in some 
>> form, unfortunately; see https://trac.sagemath.org/ticket/7964 for a 
>> related ticket.   See https://trac.sagemath.org/ticket/30983 for a 
>> ticket that complains instead about something else but which is closely 
>> related.
>>
>> We would be grateful for any additional insight you might provide.  Here 
>> are some pieces of info about where we use matplotlib that you might find 
>> useful in that regard.
>>
>> We use some specific matplotlib ticker and formatter options which don't 
>> always play well here.  See 
>> https://github.com/sagemath/sage/blob/develop/src/sage/plot/graphics.py#L2326
>>  
>> for _matplotlib_tick_formatter in sage/plot/graphics.py
>>
>> In particular, note that, under ordinary circumstances,
>>
>> y_locator = MaxNLocator(**locator_options)
>> y_formatter = ScalarFormatter()
>>
>> That is very close to the defaults for matplotlib, but maybe we are using 
>> things in an antiquated way.  See e.g. 
>> https://matplotlib.org/stable/api/ticker_api.html#matplotlib.ticker.ScalarFormatter
>>  
>>
>> On the other hand, if (as I suspect) that isn't the root issue, it 
>> probably is in the save method (
>> https://github.com/sagemath/sage/blob/develop/src/sage/plot/graphics.py#L3198).
>>  
>>  My first thought was that somehow fig_tight played a role, but 
>>
>> sage: plot(x^2,(x,0,5000),fig_tight=False)
>>
>> doesn't seem to be any different than the one you pointed out.  Another 
>> possibility is tight_layout (
>> https://matplotlib.org/stable/api/tight_layout_api.html) which we do 
>> use, but which a little experimentation doesn't seem to indicate is the 
>> problem either.
>> On Tuesday, July 26, 2022 at 5:15:11 AM UTC-4 niran...@gmail.com wrote:
>>
>>> Dear all,
>>> "2D plotting" doc says,
>>> "Another thing to be aware of with axis labeling is that when the labels 
>>> have quite different orders of magnitude or are very large, scientific 
>>> notation (the e  notation for powers of ten) is used."
>>>
>>> But display of this multiplier power for the scaled y-axis is missing if 
>>> the plot starts with x=0 or at most will be missing till the x-axis 
>>> detaches from the origin. Following examples illustrates it,
>>>
>>> *sage:*  plot(x^2,(x,0,5000))  # missing display of 1e7 above y-axis
>>> *sage:*  plot(x^2,(x,50,5000))  # missing display of 1e7 above y-axis
>>> *sage:*  plot(x^2,(x,100,5000))  # display of 1e7 above y-axis is 
>>> visible
>>>
>>> On the other side matplotlib natively always displays the scale 
>>> multiplier (if any) whenever numbers are large. For example:
>>>
>>> *sage:*  import matplotlib.pyplot as plt
>>> *sage:*  import numpy as np
>>> *sage:*  z = np.linspace(0, 5000, 100)
>>> *sage:*  plt.plot(z, z**2)
>>> *sage:*  plt.show()
>>>
>>> My other plots involved electric field calculations which had magnitudes 
>>> around 1/epsilon_0 which is 1/(8.85E-12) =~ 10^11. For those plots starting 
>>> with x=0 the display of multiplier used for y-axis were missing.
>>>
>>> With regards
>>> Niranjana
>>>
>> ​

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sage-devel/5c00353d-3948-4f61-9a19-60baf5118965n%40googlegroups.com.


[sage-devel] Re: Display of scale multiplier in scientific notation (the e notation for powers of ten) is missing for plots starting with 0

2022-07-27 Thread Niranjana K M
Dear Kcrisman,
I will look into it *if* you promise me to *review* and *close* my 
another ticket   https://trac.sagemath.org/ticket/34038
based on the thread   
https://groups.google.com/g/sage-devel/c/tMH1RZNyC9s/m/DRwexGpzAwAJ
 

With regards
Niranjana

On Wednesday, July 27, 2022 at 7:05:51 PM UTC+5:30 kcrisman wrote:

> This is a good question, and one that has been around for a while in some 
> form, unfortunately; see https://trac.sagemath.org/ticket/7964 for a 
> related ticket.   See https://trac.sagemath.org/ticket/30983 for a ticket 
> that complains instead about something else but which is closely related.
>
> We would be grateful for any additional insight you might provide.  Here 
> are some pieces of info about where we use matplotlib that you might find 
> useful in that regard.
>
> We use some specific matplotlib ticker and formatter options which don't 
> always play well here.  See 
> https://github.com/sagemath/sage/blob/develop/src/sage/plot/graphics.py#L2326 
> for _matplotlib_tick_formatter in sage/plot/graphics.py
>
> In particular, note that, under ordinary circumstances,
>
> y_locator = MaxNLocator(**locator_options)
> y_formatter = ScalarFormatter()
>
> That is very close to the defaults for matplotlib, but maybe we are using 
> things in an antiquated way.  See e.g. 
> https://matplotlib.org/stable/api/ticker_api.html#matplotlib.ticker.ScalarFormatter
>  
>
> On the other hand, if (as I suspect) that isn't the root issue, it 
> probably is in the save method (
> https://github.com/sagemath/sage/blob/develop/src/sage/plot/graphics.py#L3198).
>  
>  My first thought was that somehow fig_tight played a role, but 
>
> sage: plot(x^2,(x,0,5000),fig_tight=False)
>
> doesn't seem to be any different than the one you pointed out.  Another 
> possibility is tight_layout (
> https://matplotlib.org/stable/api/tight_layout_api.html) which we do use, 
> but which a little experimentation doesn't seem to indicate is the problem 
> either.
> On Tuesday, July 26, 2022 at 5:15:11 AM UTC-4 niran...@gmail.com wrote:
>
>> Dear all,
>> "2D plotting" doc says,
>> "Another thing to be aware of with axis labeling is that when the labels 
>> have quite different orders of magnitude or are very large, scientific 
>> notation (the e  notation for powers of ten) is used."
>>
>> But display of this multiplier power for the scaled y-axis is missing if 
>> the plot starts with x=0 or at most will be missing till the x-axis 
>> detaches from the origin. Following examples illustrates it,
>>
>> *sage:*  plot(x^2,(x,0,5000))  # missing display of 1e7 above y-axis
>> *sage:*  plot(x^2,(x,50,5000))  # missing display of 1e7 above y-axis
>> *sage:*  plot(x^2,(x,100,5000))  # display of 1e7 above y-axis is visible
>>
>> On the other side matplotlib natively always displays the scale 
>> multiplier (if any) whenever numbers are large. For example:
>>
>> *sage:*  import matplotlib.pyplot as plt
>> *sage:*  import numpy as np
>> *sage:*  z = np.linspace(0, 5000, 100)
>> *sage:*  plt.plot(z, z**2)
>> *sage:*  plt.show()
>>
>> My other plots involved electric field calculations which had magnitudes 
>> around 1/epsilon_0 which is 1/(8.85E-12) =~ 10^11. For those plots starting 
>> with x=0 the display of multiplier used for y-axis were missing.
>>
>> With regards
>> Niranjana
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sage-devel/33ada506-b846-4929-8901-712821a85f1an%40googlegroups.com.


[sage-devel] Re: Display of scale multiplier in scientific notation (the e notation for powers of ten) is missing for plots starting with 0

2022-07-27 Thread kcrisman
This is a good question, and one that has been around for a while in some 
form, unfortunately; see https://trac.sagemath.org/ticket/7964 for a 
related ticket.   See https://trac.sagemath.org/ticket/30983 for a ticket 
that complains instead about something else but which is closely related.

We would be grateful for any additional insight you might provide.  Here 
are some pieces of info about where we use matplotlib that you might find 
useful in that regard.

We use some specific matplotlib ticker and formatter options which don't 
always play well here. 
 See 
https://github.com/sagemath/sage/blob/develop/src/sage/plot/graphics.py#L2326 
for _matplotlib_tick_formatter in sage/plot/graphics.py

In particular, note that, under ordinary circumstances,

y_locator = MaxNLocator(**locator_options)
y_formatter = ScalarFormatter()

That is very close to the defaults for matplotlib, but maybe we are using 
things in an antiquated way.  See 
e.g. 
https://matplotlib.org/stable/api/ticker_api.html#matplotlib.ticker.ScalarFormatter
 

On the other hand, if (as I suspect) that isn't the root issue, it probably 
is in the save method 
(https://github.com/sagemath/sage/blob/develop/src/sage/plot/graphics.py#L3198).
 
 My first thought was that somehow fig_tight played a role, but 

sage: plot(x^2,(x,0,5000),fig_tight=False)

doesn't seem to be any different than the one you pointed out.  Another 
possibility is tight_layout 
(https://matplotlib.org/stable/api/tight_layout_api.html) which we do use, 
but which a little experimentation doesn't seem to indicate is the problem 
either.
On Tuesday, July 26, 2022 at 5:15:11 AM UTC-4 niran...@gmail.com wrote:

> Dear all,
> "2D plotting" doc says,
> "Another thing to be aware of with axis labeling is that when the labels 
> have quite different orders of magnitude or are very large, scientific 
> notation (the e  notation for powers of ten) is used."
>
> But display of this multiplier power for the scaled y-axis is missing if 
> the plot starts with x=0 or at most will be missing till the x-axis 
> detaches from the origin. Following examples illustrates it,
>
> *sage:*  plot(x^2,(x,0,5000))  # missing display of 1e7 above y-axis
> *sage:*  plot(x^2,(x,50,5000))  # missing display of 1e7 above y-axis
> *sage:*  plot(x^2,(x,100,5000))  # display of 1e7 above y-axis is visible
>
> On the other side matplotlib natively always displays the scale multiplier 
> (if any) whenever numbers are large. For example:
>
> *sage:*  import matplotlib.pyplot as plt
> *sage:*  import numpy as np
> *sage:*  z = np.linspace(0, 5000, 100)
> *sage:*  plt.plot(z, z**2)
> *sage:*  plt.show()
>
> My other plots involved electric field calculations which had magnitudes 
> around 1/epsilon_0 which is 1/(8.85E-12) =~ 10^11. For those plots starting 
> with x=0 the display of multiplier used for y-axis were missing.
>
> With regards
> Niranjana
>

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sage-devel/146eb3ef-49bf-4f06-8e40-3c21c7a67bd5n%40googlegroups.com.