Skip to content

Commit 54bb4ba

Browse files
authored
remove the visible call of glue in the saving section (#109)
* remove the visible call of in the saving section * remove size calculation code
1 parent 0b48805 commit 54bb4ba

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

source/viz.md

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ visualization. Let's create a scatter plot using the `altair`
508508
package with the `waiting` variable on the horizontal axis, the `eruptions`
509509
variable on the vertical axis, and the `mark_point` geometric object.
510510
By default, `altair` draws only the outline of each point. If we would
511-
like to fill them in, we pass the argument `filled=True` to `mark_point`. In
511+
like to fill them in, we pass the argument `filled=True` to `mark_point`. In
512512
place of `mark_point(filled=True)`, we can also use `mark_circle`.
513513
The result is shown in {numref}`faithful_scatter`.
514514

@@ -1225,9 +1225,9 @@ The plot in {numref}`islands_plot_sorted` is now a very effective
12251225
visualization for answering our original questions. Landmasses are organized by
12261226
their size, and continents are colored differently than other landmasses,
12271227
making it quite clear that continents are the largest seven landmasses.
1228-
We can make one more finishing touch in {numref}`islands_plot_titled`: we will
1228+
We can make one more finishing touch in {numref}`islands_plot_titled`: we will
12291229
add a title to the chart by specifying `title` argument in the `alt.Chart` function.
1230-
Note that plot titles are not always required; usually plots appear as part
1230+
Note that plot titles are not always required; usually plots appear as part
12311231
of other media (e.g., in a slide presentation, on a poster, in a paper) where
12321232
the title may be redundant with the surrounding context.
12331233

@@ -1353,10 +1353,10 @@ Note that
13531353
*vertical lines* are used to denote quantities on the *horizontal axis*,
13541354
while *horizontal lines* are used to denote quantities on the *vertical axis*.
13551355

1356-
To add the dashed line on top of the histogram, we
1357-
**add** the `mark_rule` chart to the `morley_hist`
1356+
To add the dashed line on top of the histogram, we
1357+
**add** the `mark_rule` chart to the `morley_hist`
13581358
using the `+` operator.
1359-
Adding features to a plot using the `+` operator is known as *layering* in `altair`.
1359+
Adding features to a plot using the `+` operator is known as *layering* in `altair`.
13601360
This is a very powerful feature of `altair`; you
13611361
can continue to iterate on a single plot object, adding and refining
13621362
one layer at a time. If you stored your plot as a named object
@@ -1446,7 +1446,7 @@ To fix this issue we can convert the `Expt` variable into a `nominal`
14461446
(i.e., categorical) type variable by adding a suffix `:N`
14471447
to the `Expt` variable. Adding the `:N` suffix ensures that `altair`
14481448
will treat a variable as a categorical variable, and
1449-
hence use a discrete color map in visualizations.
1449+
hence use a discrete color map in visualizations.
14501450
We also specify the `stack=False` argument in the `y` encoding so
14511451
that the bars are not stacked on top of each other.
14521452

@@ -1831,8 +1831,8 @@ perfectly re-created when loading and displaying, with the hope that the change
18311831
is not noticeable. *Lossless* formats, on the other hand, allow a perfect
18321832
display of the original image.
18331833

1834-
- *Common file types:*
1835-
- [JPEG](https://en.wikipedia.org/wiki/JPEG) (`.jpg`, `.jpeg`): lossy, usually used for photographs
1834+
- *Common file types:*
1835+
- [JPEG](https://en.wikipedia.org/wiki/JPEG) (`.jpg`, `.jpeg`): lossy, usually used for photographs
18361836
- [PNG](https://en.wikipedia.org/wiki/Portable_Network_Graphics) (`.png`): lossless, usually used for plots / line drawings
18371837
- [BMP](https://en.wikipedia.org/wiki/BMP_file_format) (`.bmp`): lossless, raw image data, no compression (rarely used)
18381838
- [TIFF](https://en.wikipedia.org/wiki/TIFF) (`.tif`, `.tiff`): typically lossless, no compression, used mostly in graphic arts, publishing
@@ -1845,8 +1845,8 @@ display of the original image.
18451845
objects (lines, surfaces, shapes, curves). When the computer displays the image, it
18461846
redraws all of the elements using their mathematical formulas.
18471847

1848-
- *Common file types:*
1849-
- [SVG](https://en.wikipedia.org/wiki/Scalable_Vector_Graphics) (`.svg`): general-purpose use
1848+
- *Common file types:*
1849+
- [SVG](https://en.wikipedia.org/wiki/Scalable_Vector_Graphics) (`.svg`): general-purpose use
18501850
- [EPS](https://en.wikipedia.org/wiki/Encapsulated_PostScript) (`.eps`), general-purpose use (rarely used)
18511851
- *Open-source software:* [Inkscape](https://inkscape.org/)
18521852

@@ -1875,7 +1875,7 @@ Let's learn how to save plot images to `.png` and `.svg` file formats using the
18751875
`faithful_scatter_labels` scatter plot of the [Old Faithful data set](https://www.stat.cmu.edu/~larry/all-of-statistics/=data/faithful.dat)
18761876
{cite:p}`faithfuldata` that we created earlier, shown in {numref}`faithful_scatter_labels`.
18771877
To save the plot to a file, we can use the `save`
1878-
method. The `save` method takes the path to the filename where you would like to
1878+
method. The `save` method takes the path to the filename where you would like to
18791879
save the file (e.g., `img/filename.png` to save a file named `filename.png` to the `img` directory).
18801880
The kind of image to save is specified by the file extension. For example, to
18811881
create a PNG image file, we specify that the file extension is `.png`. Below
@@ -1891,6 +1891,7 @@ faithful_scatter_labels.save("img/faithful_plot.svg")
18911891
```
18921892

18931893
```{code-cell} ipython3
1894+
:tags: [remove-cell]
18941895
import os
18951896
import numpy as np
18961897
png_size = np.round(os.path.getsize("img/faithful_plot.png")/(1024*1024), 2)
@@ -1916,9 +1917,9 @@ glue("svg_size", svg_size)
19161917
```
19171918

19181919
Take a look at the file sizes in {numref}`png-vs-svg-table`
1919-
Wow, that's quite a difference! In this case, the `.png` image is almost 4 times
1920+
Wow, that's quite a difference! In this case, the `.png` image is almost 4 times
19201921
smaller than the `.svg` image. Since there are a decent number of points in the plot,
1921-
the vector graphics format image (`.svg`) is bigger than the raster image (`.png`), which
1922+
the vector graphics format image (`.svg`) is bigger than the raster image (`.png`), which
19221923
just stores the image data itself.
19231924
In {numref}`png-vs-svg`, we show what
19241925
the images look like when we zoom in to a rectangle with only 3 data points.

0 commit comments

Comments
 (0)