scipy-lectures / scientific-python-lectures

Tutorial material on the scientific Python ecosystem
https://lectures.scientific-python.org
Other
3.11k stars 1.19k forks source link

Replace old figure with generated one #262

Open emmanuelle opened 8 years ago

emmanuelle commented 8 years ago

Figure http://www.scipy-lectures.org/_images/random_c.jpg is not so nice and a static file (disclaimer: it's an old figure from my PhD work =p). It would be better to replace it with a cool figure generated from a Python script.

GaelVaroquaux commented 8 years ago

Maybe bessel functions, as in the following Chaco plot: http://docs.enthought.com/chaco/user_manual/annotated_examples.html#bigdata-py

gertingold commented 7 years ago

It would be nice to have figures for which the relation to the packages is more obvious. Following the suggestion of displaying Bessel functions, such a figure would nicely relate to the SciPy package, while a second image of a (random?) matrix using imshow could be appropriate for NumPy.

lawrencefchan commented 4 years ago

Has this been implemented anywhere in the code? I'm looking for examples to create a consistent style, but I haven't been able to find any.

In the example given in how to contribute it doesn't look like there is a reference to plot_xxx.py.

pdebuyl commented 4 years ago

Thank you for the comment. The practice has been used to progressively replace the content but we have not documented it yet.

For the example you are working on, you can look at the file stats-interpolate.rst in the same directory, it uses the updated technique.

In short:

  1. create a directory named "examples" (already done for the directory here).
  2. Add a README.rst (necessary for sphinx-gallery)
  3. add a file plot_XXX.py with a top "docstring" (a short description between triple quotes)
  4. write the code to generate a figure

the figure will be named "auto_examples/images/sphx_glr_plot_XXX_001.png" (numbering from 001 onwards if several figures).

pdebuyl commented 2 years ago

Proposal: add fives terms for a Fourier series. Quite simple and visual.

import numpy as np
import matplotlib.pyplot as plt

x = np.linspace(0, 2, 201)
terms = [-np.sin(k*2*np.pi*x)*(-1)**k for k in [1, 2, 3, 4, 5]]
series = np.sum(terms, axis=0)
[plt.plot(x, terms[i], alpha=1/(i+1)) for i in range(len(terms))]
plt.plot(x, series)

plt.show()