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

[BUG] Subplot aspect ratio #263

Open
philsw opened this issue Apr 13, 2023 · 1 comment
Open

[BUG] Subplot aspect ratio #263

philsw opened this issue Apr 13, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@philsw
Copy link

philsw commented Apr 13, 2023

Hello,
I am not able to change the aspect ratio of the subplot generated by plot_nyquist function. The size can be altered, but the aspect ratio is always around 1:5, regardless of x and y in fig, ax = plt.subplots(figsize = (x,y)). I used readBioLogic funciton to read.mpt files and changed the equivalent circuit, otherwise the script is identical to the getting_started script. Strangely, the plot size and ratio can be altered in the getting_started script, but not in my script.
Thanks so much for your help.

Full code:

from impedance import preprocessing
import matplotlib.pyplot as plt
from impedance.visualization import plot_nyquist

frequencies, Z = preprocessing.readBioLogic('../data/file.mpt')

frequencies, Z = preprocessing.ignoreBelowX(frequencies, Z)

from impedance.models.circuits import CustomCircuit

initial_guess = [20,0.8,5]
circuit = CustomCircuit('R0-p(R1,CPE1)-Wo1-C1', initial_guess=initial_guess, constants={'R0': 0.9, "R1": 1.32,"Wo1_0": 8.4,"Wo1_1":24})

circuit.fit(frequencies, Z)
Z_fit = circuit.predict(frequencies)

fig, ax = plt.subplots(figsize = (20,8))

plot_nyquist(Z, fmt='o', ax=ax, scale = 1)
plot_nyquist(Z_fit, fmt='-', ax=ax, scale = 1)

plt.legend(['Data', 'Fit'])
plt.show()
@philsw philsw added the bug Something isn't working label Apr 13, 2023
@mdmurbach
Copy link
Member

Hi @philsw, I believe the issue here is that we use ax.set_aspect('equal') to make the aspect ratio square (as is typical in Nyquist plots). You can override this by setting the aspect ratio in matplotlib to 'auto' which should allow the ratio to be defined by whatever figsize you specify instead

fig, ax = plt.subplots(figsize = (20,8))

plot_nyquist(Z, fmt='o', ax=ax, scale = 1)
plot_nyquist(Z_fit, fmt='-', ax=ax, scale = 1)
ax.set_aspect('auto')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants