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

Context manager for plots is not working with dicts #400

Closed
sikersten opened this issue Dec 7, 2022 · 1 comment
Closed

Context manager for plots is not working with dicts #400

sikersten opened this issue Dec 7, 2022 · 1 comment
Assignees
Labels
bug For bugs not on the master branch merged plot

Comments

@sikersten
Copy link
Member

sikersten commented Dec 7, 2022

General

  • pyfar version: 0.5.1

Description

It seems like the plot functions work in combination with_pyfar.plot.context()_ (and matplotlib.style.context()) with styles as input:

import pyfar as pf
import matplotlib as mpl
import matplotlib.pyplot as plt
pf.plot.use()

with pf.plot.context('classic'):
    fig, ax = plt.subplots(2, 1)
    pf.plot.time(pf.TimeData([0, 1, 0, -1], range(4)), ax=ax[0])
    ax[1].plot(range(4), [0, 1, 0, -1])

grafik

But not with dicts as arguments:

import pyfar as pf
import matplotlib as mpl
import matplotlib.pyplot as plt
pf.plot.use()

with pf.plot.context({'lines.linestyle': ':'}):
    fig, ax = plt.subplots(2, 1)
    pf.plot.time(pf.TimeData([0, 1, 0, -1], range(4)), ax=ax[0])
    ax[1].plot(range(4), [0, 1, 0, -1])

grafik

I suppose the reason is that for example the linestyle is overwritten by the call of pyfar.plot.context() within the plot function. In constrast, this works well:

import pyfar as pf
import matplotlib as mpl
import matplotlib.pyplot as plt
pf.plot.use()

style = {'lines.linestyle': ':'}

fig, ax = plt.subplots(2, 1)
pf.plot.time(pf.TimeData([0, 1, 0, -1], range(4)), ax=ax[0], style=style)
ax[1].plot(range(4), [0, 1, 0, -1])

grafik

@sikersten sikersten added bug For bugs not on the master branch plot labels Dec 7, 2022
@github-actions github-actions bot added this to To do in Code Backlog Dec 7, 2022
@sikersten sikersten changed the title Context manager for plot is not working with dicts Context manager for plots is not working with dicts Dec 7, 2022
@sikersten
Copy link
Member Author

We discussed that there is not really a solution without calling the plot functions with a style=... parameter.
This includes the solution for avoiding all properties of the pyfar plot styles by calling with an empty dict style={}.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug For bugs not on the master branch merged plot
Projects
Development

No branches or pull requests

3 participants