GitHub

@@ -354,7 +354,7 @@ You can use the function to experiment with other styles in the list.

354354355355

If you are interested, you can even create your own style sheets.

356356357-

Paraeters for your style sheets are stored in a dictionary-like variable `plt.rcParams`

357+

Parameters for your style sheets are stored in a dictionary-like variable `plt.rcParams`

358358359359

```{code-cell} python3

360360

---

@@ -380,14 +380,27 @@ from cycler import cycler

380380

# set to the default style sheet

381381

plt.style.use('default')

382382383+

#set default figure size

384+

plt.rcParams["figure.figsize"] = (10, 6)

383385

# update linewidth

384386

plt.rcParams['lines.linewidth'] = 2

385387

# add horizontal grid lines

386388

plt.rcParams['axes.grid'] = True

387389

plt.rcParams['axes.grid.axis'] = 'y'

388390

# update colors for density lines

389-

plt.rcParams['axes.prop_cycle'] = cycler('color', ['dimgray', 'slategrey', 'darkgray'])

391+

plt.rcParams['axes.prop_cycle'] = cycler('color',

392+

['dimgray', 'slategrey', 'darkgray'])

393+

```

394+395+

```{note}

396+397+

These settings are `global`.

398+399+

Any plot generated after changing parameters in `.rcParams` will be affected by the setting.

390400401+

```

402+403+

```{code-cell} python3

391404

fig, ax = plt.subplots()

392405

x = np.linspace(-4, 4, 150)

393406

for i in range(3):

@@ -397,11 +410,22 @@ for i in range(3):

397410

ax.plot(x, y, linewidth=2, alpha=0.6, label=current_label)

398411

ax.legend()

399412

plt.show()

413+

```

414+415+

Apply the `default` style sheet again to change your style back to default

416+417+

```{code-cell} python3

418+419+

plt.style.use('default')

420+421+

#set default figure size

422+

plt.rcParams["figure.figsize"] = (10, 6)

400423401424

```

402425403426

Here are [more examples](https://www.datafantic.com/the-magic-of-matplotlib-stylesheets/) on how to change these parameters.

404427428+405429

## Further Reading

406430407431

* The [Matplotlib gallery](http://matplotlib.org/gallery.html) provides many examples.

Read the original on github.com ↗