Skip to content
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

No enforced matplotlib styles #99

Merged
merged 4 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ numpy
pandas
praat-parselmouth
scipy
seaborn
sounddevice
8 changes: 4 additions & 4 deletions docs/source/examples/snippets/autocorrelation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -234,9 +234,9 @@
"# Make isochronous sequence\n",
"seq_isoc = Sequence.generate_isochronous(n_events=20, ioi=peaks[0])\n",
"\n",
"fig, ax = plot_multiple_sequences([seq_isoc, seq], \n",
"fig, ax = plot_multiple_sequences([seq_isoc, seq],\n",
" figsize=(10, 4),\n",
" y_axis_labels=['Theoretical beat', 'Random sequence'], \n",
" y_axis_labels=['Theoretical beat', 'Random sequence'],\n",
" suppress_display=True)\n",
"\n",
"\n",
Expand Down Expand Up @@ -306,7 +306,7 @@
"metadata": {
"celltoolbar": "Raw-celnotatie",
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "venv",
"language": "python",
"name": "python3"
},
Expand All @@ -320,7 +320,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.9.6"
}
},
"nbformat": 4,
Expand Down
2 changes: 1 addition & 1 deletion docs/source/examples/snippets/export_ioi_df.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "venv",
"language": "python",
"name": "python3"
},
Expand Down
9 changes: 6 additions & 3 deletions docs/source/examples/snippets/plot_phase_differences.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -298,18 +298,21 @@
"id": "ca7612d3-7ae2-4939-aaea-7f6afa83187b",
"metadata": {
"raw_mimetype": "text/restructuredtext",
"tags": []
"tags": [],
"vscode": {
"languageId": "raw"
}
},
"source": [
"The package documentation describes different customization options (e.g. setting the direction of 0 differently). You can find it here: :py:func:`thebeat.visualization.plot_phase_differences`.\n",
"\n",
"You may also want to take a look at the more general page :ref:`Saving and manipulating plots`."
"You may also want to take a look at the more general page :ref:`Plotting: saving, manipulating, adding styles`."
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "venv",
"language": "python",
"name": "python3"
},
Expand Down
21 changes: 4 additions & 17 deletions docs/source/examples/snippets/plot_single_sequence.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -94,19 +94,6 @@
"As you might have noticed in the example above, we passed the ``plot_sequence`` method the argument ``x_axis_label``. This is one of the so-called keyword arguments (``**kwargs``) that can be supplied to most of the plotting functions in this package. For a reference, see e.g. :py:func:`thebeat.helpers.plot_single_sequence`."
]
},
{
"cell_type": "raw",
"metadata": {
"pycharm": {
"name": "#%% md\n"
},
"raw_mimetype": "text/restructuredtext"
},
"source": [
"Now we can adjust the plot a little already by passing the :py:meth:`~thebeat.core.Sequence.plot_sequence` method a ``title``, a `matplotlib style <https://matplotlib.org/stable/gallery/style_sheets/style_sheets_reference.html>`_,\n",
"a ``linewidth``, and an output size of the figure (in inches). How to additionally adjust the plot we learn at the end of this snippet."
]
},
{
"cell_type": "code",
"execution_count": null,
Expand All @@ -118,7 +105,7 @@
"outputs": [],
"source": [
"seq = Sequence.generate_isochronous(n_events=5, ioi=500)\n",
"seq.plot_sequence(style='seaborn-v0_8-paper', title='My awesome sequence', linewidth=100, figsize=(4, 2));"
"seq.plot_sequence(title='My awesome sequence', linewidth=100, figsize=(4, 2));"
]
},
{
Expand Down Expand Up @@ -159,7 +146,7 @@
"stimseq = SoundSequence(stims, seq)\n",
"\n",
"# And plot!\n",
"stimseq.plot_sequence(style='bmh', title='Random StimSeq');"
"stimseq.plot_sequence(title='Random StimSeq');"
]
},
{
Expand Down Expand Up @@ -187,7 +174,7 @@
"outputs": [],
"source": [
"seq = Sequence.from_onsets([200, 500, 1000, 1400, 2300])\n",
"seq.plot_sequence(title = \"Non-zero first onset\", figsize = (8,3), style=\"seaborn-v0_8-ticks\");"
"seq.plot_sequence(title = \"Non-zero first onset\", figsize = (8,3));"
]
},
{
Expand Down Expand Up @@ -253,7 +240,7 @@
"Plotting onto an existing Axes object\n",
"-------------------------------------\n",
"\n",
"Finally, sometimes it is useful to be able to create a *matplotlib* :class:`~matplotlib.axes.Axes` and :class:`~matplotlib.figure.Figure` object first, and then use one of the plotting functions of *thebeat* to plot onto it. This we can do by passing the existing :class:`~matplotlib.axes.Axes` object to the ``ax`` parameter. Below is an example. The ``tight_layout`` parameter makes sure all the labels are plotted nicely. "
"Finally, sometimes it is useful to be able to create a *matplotlib* :class:`~matplotlib.axes.Axes` and :class:`~matplotlib.figure.Figure` object first, and then use one of the plotting functions of *thebeat* to plot onto it. This we can do by passing the existing :class:`~matplotlib.axes.Axes` object to the ``ax`` parameter. Below is an example. The ``tight_layout`` parameter makes sure all the labels are plotted nicely."
]
},
{
Expand Down
144 changes: 126 additions & 18 deletions docs/source/examples/tipstricks/manipulate_plots.ipynb
Original file line number Diff line number Diff line change
@@ -1,11 +1,27 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "bbeac28b-faed-45c2-b46b-2bae803318a8",
"metadata": {
"nbsphinx": "hidden",
"tags": []
},
"outputs": [],
"source": [
"import warnings\n",
"warnings.filterwarnings('ignore', message=\"Matplotlib \")\n",
"warnings.filterwarnings('ignore', message=\"FixedFormatter \")\n",
"%matplotlib inline"
]
},
{
"cell_type": "markdown",
"id": "b9cd0898-9bc0-4f1a-88d3-e07b7727d240",
"metadata": {},
"source": [
"# Saving and manipulating plots"
"# Plotting: saving, manipulating, adding styles"
]
},
{
Expand All @@ -21,39 +37,131 @@
},
{
"cell_type": "markdown",
"id": "697f730a-21d7-4496-aeb7-c692d64628c6",
"metadata": {},
"id": "1d4a1025",
"metadata": {
"vscode": {
"languageId": "raw"
}
},
"source": [
"---\n",
"\n",
"## Saving plots"
"## Adding a style/theme to the plot\n",
"\n",
"For adding an existing style to a plot we can do one of two things:\n",
"\n",
"1. We use a 'context manager' to temporarily set the style, make the plot we want, and then continue in the default style.\n",
"2. Set the theme options globally in the document. Note that until _Matplotlib_ is imported again, this style will apply to all plots (created by\n",
"_thebeat_, _Matplotlib_, or something else that uses _Matplotlib_ internally).\n",
"\n",
"There's standard [_Matplotlib_ styles](https://matplotlib.org/stable/gallery/style_sheets/style_sheets_reference.html) that we can use,\n",
"or we can use the (slightly prettier) standard styles from [_Seaborn_](https://seaborn.pydata.org/tutorial/aesthetics.html). Both options are illustrated below,\n",
"note that you have to install _Seaborn_ separately in order to use those styles (using e.g. ``pip install seaborn``)."
]
},
{
"cell_type": "raw",
"id": "e72b7277-30a3-48e9-b486-1e44611ac742",
"cell_type": "markdown",
"id": "122ab17c",
"metadata": {
"raw_mimetype": "text/restructuredtext",
"tags": []
"vscode": {
"languageId": "raw"
}
},
"source": [
"In the example below we create a recurrence plot, and save it to disk using :meth:`~matplotlib.figure.Figure.savefig`. We ask for a plot with a dpi of 600, so we get better quality."
"### Temporarily use a different style\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "bbeac28b-faed-45c2-b46b-2bae803318a8",
"id": "7f6ff735",
"metadata": {},
"outputs": [],
"source": [
"# Using a Matplotlib style\n",
"import thebeat\n",
"import matplotlib.pyplot as plt\n",
"\n",
"seq = thebeat.Sequence(iois=[200, 500, 1000])\n",
"\n",
"# Plot using a context manager\n",
"with plt.style.context('ggplot'):\n",
" seq.plot_sequence()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "7855bf4d",
"metadata": {},
"outputs": [],
"source": [
"# Using a Seaborn style\n",
"import thebeat\n",
"import seaborn as sns\n",
"\n",
"seq = thebeat.Sequence(iois=[200, 500, 1000])\n",
"\n",
"# Plot using Seaborn's context manager\n",
"with sns.axes_style('dark'):\n",
" seq.plot_sequence()"
]
},
{
"cell_type": "markdown",
"id": "3161abe4",
"metadata": {},
"source": [
"### Set style globally"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "43d5a7b1",
"metadata": {},
"outputs": [],
"source": [
"# Using a Matplotlib style globally\n",
"import thebeat\n",
"import matplotlib.pyplot as plt\n",
"\n",
"plt.style.use('ggplot')"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c24715dd",
"metadata": {},
"outputs": [],
"source": [
"# Using a Seaborn style globally\n",
"import thebeat\n",
"import seaborn as sns\n",
"\n",
"sns.set_style('dark')"
]
},
{
"cell_type": "markdown",
"id": "697f730a-21d7-4496-aeb7-c692d64628c6",
"metadata": {},
"source": [
"---\n",
"\n",
"## Saving plots"
]
},
{
"cell_type": "raw",
"id": "e72b7277-30a3-48e9-b486-1e44611ac742",
"metadata": {
"nbsphinx": "hidden",
"raw_mimetype": "text/restructuredtext",
"tags": []
},
"outputs": [],
"source": [
"import warnings\n",
"warnings.filterwarnings('ignore', message=\"Matplotlib \")\n",
"warnings.filterwarnings('ignore', message=\"FixedFormatter \")\n",
"%matplotlib inline"
"In the example below we create a recurrence plot, and save it to disk using :meth:`~matplotlib.figure.Figure.savefig`. We ask for a plot with a dpi of 600, so we get better quality."
]
},
{
Expand Down Expand Up @@ -136,7 +244,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "venv",
"language": "python",
"name": "python3"
},
Expand All @@ -150,7 +258,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.4"
"version": "3.9.6"
}
},
"nbformat": 4,
Expand Down
2 changes: 1 addition & 1 deletion docs/source/lookuptable/data_visualization.csv
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ Musical notation,:py:class:`~thebeat.music.Rhythm`,:py:meth:`~thebeat.music.Rhyt
Musical notation,:py:class:`~thebeat.music.Melody`,:py:meth:`~thebeat.music.Melody.plot_melody`,
Phase differences,:py:class:`~thebeat.core.Sequence`,:py:func:`~thebeat.visualization.plot_phase_differences`,:ref:`Plotting phase differences (circular plots)`
Phase space plot,:py:class:`~thebeat.core.Sequence`,:py:func:`~thebeat.visualization.phase_space_plot`,
Recurrence plot,:py:class:`~thebeat.core.Sequence`,:py:func:`~thebeat.visualization.recurrence_plot`,:ref:`Saving and manipulating plots`
Recurrence plot,:py:class:`~thebeat.core.Sequence`,:py:func:`~thebeat.visualization.recurrence_plot`,":ref:`Plotting: saving, manipulating, adding styles`"
Waveform,:py:class:`~thebeat.core.SoundSequence`,:py:meth:`~thebeat.core.SoundSequence.plot_waveform`,:ref:`Getting started`
Waveform,:py:class:`~thebeat.core.SoundStimulus`,:py:meth:`~thebeat.core.SoundStimulus.plot_waveform`,:ref:`Roving oddball`
Binary file modified tests/baseline/test_acf_image_milliseconds.png
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 tests/baseline/test_acf_image_seconds.png
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 tests/baseline/test_ccf_plot.png
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 tests/baseline/test_fft_plot.png
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 tests/baseline/test_interval_ratios_plot_density.png
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 tests/baseline/test_interval_ratios_plot_histogram.png
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 tests/baseline/test_lilypond_package.png
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 tests/baseline/test_melody_plot.png
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 tests/baseline/test_plot_multiple_sequences_0.png
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 tests/baseline/test_plot_multiple_sequences_1.png
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 tests/baseline/test_plot_multiple_sequences_2.png
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 tests/baseline/test_plot_multiple_sequences_3.png
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 tests/baseline/test_plot_phase_differences.png
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 tests/baseline/test_plot_sequence.png
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 tests/baseline/test_plot_sequence_title.png
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 tests/baseline/test_plot_stimulus_waveform_0.png
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 tests/baseline/test_plot_stimulus_waveform_1.png
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 tests/baseline/test_recurrence_plot_nothreshold.png
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 tests/baseline/test_recurrence_plot_threshold.png
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 tests/baseline/test_soundsequence_plot.png
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 tests/baseline/test_soundsequence_plot_sequence.png
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 tests/baseline/test_soundsequence_plot_waveform.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion tests/test_visualization.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def test_plot_multiple_sequences_0(rng):
stims = [SoundStimulus.generate() for _ in range(10)] # = 10 stimuli
trials.append(SoundSequence(stims, seq))

fig, ax = plot_multiple_sequences(trials, style="ggplot", suppress_display=True)
fig, ax = plot_multiple_sequences(trials, suppress_display=True)

return fig

Expand Down
Loading
Loading