Skip to content

Commit

Permalink
new lines
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeldorman committed Jul 29, 2023
1 parent 7e9241d commit 9cbe7e6
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 44 deletions.
9 changes: 6 additions & 3 deletions 08-read-write-plot.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,8 @@ In such cases, the same considerations shown for `int` apply to `float` rasters

## Visual outputs {#sec-visual-outputs}

Visual outputs can be exported to a file using the [`plt.savefig`](https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.savefig.html) function. For example, the following code section recreates @fig-read-shp-query (see above), but this time the last expression saves the image to a JPG image named `plot_geopandas.jpg`:
Visual outputs can be exported to a file using the [`plt.savefig`](https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.savefig.html) function.
For example, the following code section recreates @fig-read-shp-query (see above), but this time the last expression saves the image to a JPG image named `plot_geopandas.jpg`:

```{python}
#| output: false
Expand All @@ -658,7 +659,8 @@ tanzania_neigh.apply(lambda x: axes[1].annotate(text=x['name_long'], xy=x.geomet
plt.savefig('output/plot_geopandas.jpg')
```

Figures with rasters can be exported exactly the same way. For example, the following code section (see next chapter...) creates an image of a raster and a vector layer, which is then exported to a file named `plot_rasterio.jpg`:
Figures with rasters can be exported exactly the same way.
For example, the following code section (see next chapter...) creates an image of a raster and a vector layer, which is then exported to a file named `plot_rasterio.jpg`:

```{python}
#| output: false
Expand All @@ -669,7 +671,8 @@ nz.to_crs(nz_elev.crs).plot(ax=ax, facecolor='none', edgecolor='r');
plt.savefig('output/plot_rasterio.jpg')
```

Image file properties can be controlled through the `plt.subplots` and `plt.savefig` parameters. For example, the following code section exports the same raster plot to a file named `plot_rasterio2.svg`, which has different dimensions (width = 5 $in$, height = 7 $in$), a different format (SVG), and different resolution (300 $DPI$:)
Image file properties can be controlled through the `plt.subplots` and `plt.savefig` parameters.
For example, the following code section exports the same raster plot to a file named `plot_rasterio2.svg`, which has different dimensions (width = 5 $in$, height = 7 $in$), a different format (SVG), and different resolution (300 $DPI$:)

```{python}
#| output: false
Expand Down
82 changes: 41 additions & 41 deletions output/plot_rasterio2.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified output/world.gpkg
Binary file not shown.
Binary file modified output/world_many_features.gpkg
Binary file not shown.
Binary file modified output/world_many_layers.gpkg
Binary file not shown.

0 comments on commit 9cbe7e6

Please sign in to comment.