-
Notifications
You must be signed in to change notification settings - Fork 10
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
Image Discussion #120
Comments
Hi Lyle,
The original has two addplot commands. One to make the shaded shape,
and a second one to draw the thick line. You probably want to similarly use
two commands in a new cleaned up version too.
You should avoid using "smooth". It causes a few problems.
I agree with Lyle about using the formula for a curve when possible. It
makes
it easier for future editors. But there might be a better way to do it than
\addplot+ [...,samples=100] {1/(x^2)};
The reason you would use 100 samples is because the default is 20 (or 21?),
and with a curve like this one that has steep sections, you could get
visually
evident angles in the curve. That's because the x-domain is cut into 19 (or
20?)
equal subintervals. But the down side to using 100 samples is that it
really does
make the resulting image file larger, internally storing lots of unnecessary
coordinates. Image and file size is worth worrying about because internet
speed
can be an issue for some of the people in most need of inexpensive learning
materials.
With a curve like this one, I like to switch to hyperbolic coordinates
because the
curve is so similar to a hyperbola. That is an indicator this will work out
well.
Here is a walkthrough of the process. With
y = x^-2
Moving to hyperbolic coordinates (u, v), where
x = v e^u
y = v e^-u
You want
y = x^-2
v e^-u = (v e^u)^-2
and solving for u is easy:
v e^-u = v^-2 e^(-2u)
v^3 = e^(-u)
u = -ln(v^3)
So now use v as the parameter
x = v e^u
y = v e^-u
x = v e^(-ln(v^3))
y = v e^(-(-ln(v^3)))
x = 1/v^2
y = v^4
The original goes from x=1 to x=10.5,
so that corresponds to v=1 to v=sqrt(1/10.5) = 0.3086...
So now do:
\addplot[variable=v, domain=1:0.3086] ({1/v^2},{v^4});
…On Fri, Jul 26, 2019 at 11:36 PM Lyle ***@***.***> wrote:
This is mostly for Alex and Sean to discuss but I thought I would create
it here since it seems like it would be a good place for it. There is a
small issue with the way borders work with filling with the new method Alex
provided. In the current preamble there is a line:
\pgfplotsset{firstcurvestyle/.style={color=firstcolor,mark=none,thick,{Kite}-{Kite},solid}}
which was updated to add the ability to fill without needing to use 2
separate addplot commands (the color information was added in here instead,
before it was defined in the addplot function using {\coloronefill} which
was set to: blue!15!white) as shown below.
\pgfplotsset{firstcurvestyle/.style={color=firstcolor,mark=none,thick,{Kite}-{Kite},solid,fill=firstcolor!50,fill=none}}
Now, it is possible to convert an image like this one (from
sec_improper_integration: img_impint1a):
\begin{tikzpicture}
\begin{axis}[
axis on top,
xtick={1,5,10},
ymin=-.1,ymax=1.1,
xmin=-1,xmax=11
]
\addplot [{\coloronefill},fill={\coloronefill}] coordinates {(1.,1.)(1.5,0.4444)(2.,0.25)(2.5,0.16)(3.,0.1111)(3.5,0.08163)(4.,0.0625)(4.5,0.04938)(5.,0.04)(5.5,0.03306)(6.,0.02778)(6.5,0.02367)(7.,0.02041)(7.5,0.01778)(8.,0.01563)(8.5,0.01384)(9.,0.01235)(9.5,0.01108)(10.,0.01)(10.5,0.009)} -- (axis cs:10.5,0)--(axis cs:1,0)--cycle;
\addplot [{\colorone},thick,smooth] coordinates {(1.,1.)(1.5,0.4444)(2.,0.25)(2.5,0.16)(3.,0.1111)(3.5,0.08163)(4.,0.0625)(4.5,0.04938)(5.,0.04)(5.5,0.03306)(6.,0.02778)(6.5,0.02367)(7.,0.02041)(7.5,0.01778)(8.,0.01563)(8.5,0.01384)(9.,0.01235)(9.5,0.01108)(10.,0.01)(10.5,0.009)};
\draw (axis cs:5,.75) node {\scriptsize $\ds f(x)=\frac{1}{x^2}$};
\end{axis}
\end{tikzpicture}
Which looks like this (matching the original in the book):
[image: image]
<https://user-images.githubusercontent.com/35709572/61990569-38be6080-b000-11e9-9d09-ebbddf00f12c.png>
into:
\begin{tikzpicture}
\begin{axis}[
axis on top,
xtick={1,5,10},
ymin=-.1,ymax=1.1,
xmin=-1,xmax=11
]
\addplot+ [fill,smooth] coordinates {(1.,1.)(1.5,0.4444)(2.,0.25)(2.5,0.16)(3.,0.1111)(3.5,0.08163)(4.,0.0625)(4.5,0.04938)(5.,0.04)(5.5,0.03306)(6.,0.02778)(6.5,0.02367)(7.,0.02041)(7.5,0.01778)(8.,0.01563)(8.5,0.01384)(9.,0.01235)(9.5,0.01108)(10.,0.01)(10.5,0.009)} -- (axis cs:10.5,0)--(axis cs:1,0)--cycle;
\draw (axis cs:5,.75) node {\scriptsize $\ds f(x)=\frac{1}{x^2}$};
\end{axis}
\end{tikzpicture}
Which now looks like this image below.
[image: image]
<https://user-images.githubusercontent.com/35709572/61990557-10cefd00-b000-11e9-8da6-58f0b094f19b.png>
Notice that there is a border around the fill. I believe the issue might
lie in the cycle code at the end of the image such as:
-- (axis cs:10.5,0)--(axis cs:1,0)--cycle
in the above case or
\closedcycle
in other cases that appear in chapter 5.
As an aside for Sean (since we are on the topic). We have not discussed it
but notice that the image above is using coordinates to define its curve
when the function is obvious. In chapter 5 the images are updated to use
functions and samples instead. I can easily convert the image above to use
that form in most cases I have seen (I have kind of done some already in
chapter 6, couldn't resist). The example above when converted will be:
\begin{tikzpicture}
\begin{axis}[
axis on top,
xtick={1,5,10},
ymin=-.1,ymax=1.1,
xmin=-1,xmax=11
]
\addplot [{\coloronefill},fill={\coloronefill},domain=1:10.5,samples=100] {1/(x^2)} -- (axis cs:10.5,0) -- (axis cs:1,0) -- cycle;
\addplot [firstcurvestyle,-,domain=1:10.5,samples=100] {1/(x^2)};
\draw (axis cs:5,.75) node {\scriptsize $\ds f(x)=\frac{1}{x^2}$};
\end{axis}
\end{tikzpicture}
and if using the updated command I can shorten it to the code below.
\begin{tikzpicture}
\begin{axis}[
axis on top,
xtick={1,5,10},
ymin=-.1,ymax=1.1,
xmin=-1,xmax=11
]
\addplot+ [fill,domain=1:10.5,samples=100] {1/(x^2)} \closedcycle;
\draw (axis cs:5,.75) node {\scriptsize $\ds f(x)=\frac{1}{x^2}$};
\end{axis}
\end{tikzpicture}
This is much shorter and definitely something I want to do. Of course the
above only works if we fix the bordering issue and I would have to go back
through the images in chapter 5 and some of 6 to support the change.
My question is do you want me making those kinds of changes?
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#120?email_source=notifications&email_token=ABEDOAAXLIRIEINVR2JHPVTQBPUFPA5CNFSM4IHIRTU2YY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4HB2UWGA>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABEDOAEBO2OWT54KGMEY5HLQBPUFPANCNFSM4IHIRTUQ>
.
--
Alex Jordan
Mathematics Instructor
Portland Community College
|
Before I go into a bit of detail below I should state that I am not an experienced mathematician so tricks like the above are likely impossible for me to do given the time Sean has available for me. Firstly, that is a cool trick for certain hyperbolic functions and it definitely does same some space. I did some testing with samples and found that they seem to be inconsistent with how much they tend to add or subtract. When doing very small changes (<10) it will remove some size occasionally even when adding a few points. But on average it seems to be around 200-300 additional bytes per chunk of 10 with the difference from the default 20 and 50 being about 600-800 bytes. I also did a full compile and with the images and html (including knowls) the size for me with all 13 chapters was about 32MB. If I had to estimate with around 440 lines of coordinate defined lines with a rough average of 50 samples per line (from a previously varying amount of maybe 10-30) it is around 350KB of extra data. I also found sampling points are not really needed on area fill code in many cases so that will reduce the size as well. I also found replacing smooth with nothing or a small amount of samples, around 40 where needed, reduced the file size by around 1600 bytes on the couple I tried. We could also optimize many of the over sampled images currently in the code base to a degree but I couldn't really guess an amount as they can vary a lot (some might even need to be increased). I think this would be a much faster approach for development time and could even save additional space to what we have already as images are a very large portion of the data in the book itself. I am actually pretty impressed with how small it is currently. I would however consider even an extra MB or 2 for a considerably quicker and smoother overhaul experience a fair trade-off. I guess what I am trying to say is that we should look for different places to optimize the compiled size of the code not to mention the readability/maintainability of the code itself. Sean and I are also planning to add some interactivity to the code and it may very well add a ton of extra complexity and space (we have not done too much research on this yet so I cannot say for certain). On another note I do really like the fill changes and it definitely is the way to go for both code and space efficiency and will be updating everything I can from where we currently are in chapters 5 and 6, both partially done as of tonight. |
I was messing around and I noticed a pretty simple way is to use the domain to split the graphs up into multiple sections so we can concentrate the points where it matters. For instance we can take
and convert it to
Now we can have a clean curve with much less sampling points at a small cost of extra code. I don't think we lose any maintainability or readability since the code is very simple and the only change is the domain. Also the curves in my above example were way over sampled anyways, that particular example didn't require anything close to what I put. A bit of practice helped with that. |
This seems reasonable. In some cases you might be able to optimize with a clever substitution, but for now efficiency (w.r.t developer time) might take priority over efficiency (w.r.t. image size). |
This is mostly for Alex and Sean to discuss but I thought I would create it here since it seems like it would be a good place for it. There is a small issue with the way borders work with filling with the new method Alex provided. In the current preamble there is a line:
which was updated to add the ability to fill without needing to use 2 separate addplot commands (the color information was added in here instead, before it was defined in the addplot function using {\coloronefill} which was set to: blue!15!white) as shown below.
Now, it is possible to convert an image like this one (from sec_improper_integration: img_impint1a):
Which looks like this (matching the original in the book):
![image](https://user-images.githubusercontent.com/35709572/61990569-38be6080-b000-11e9-9d09-ebbddf00f12c.png)
into:
Which now looks like this image below.
![image](https://user-images.githubusercontent.com/35709572/61990557-10cefd00-b000-11e9-8da6-58f0b094f19b.png)
Notice that there is a border around the fill. I believe the issue might lie in the cycle code at the end of the image such as:
in the above case or
in other cases that appear in chapter 5.
As an aside for Sean (since we are on the topic). We have not discussed it but notice that the image above is using coordinates to define its curve when the function is obvious. In chapter 5 the images are updated to use functions and samples instead. I can easily convert the image above to use that form in most cases I have seen (I have kind of done some already in chapter 6, couldn't resist). The example above when converted will be:
and if using the updated command I can shorten it to the code below.
This is much shorter and definitely something I want to do. Of course the above only works if we fix the bordering issue and I would have to go back through the images in chapter 5 and some of 6 to support the change.
My question is do you want me making those kinds of changes?
The text was updated successfully, but these errors were encountered: