AguaClara / aguaclara

An open-source Python package for designing and performing research on AguaClara water treatment plants.
https://aguaclara.github.io/aguaclara/
MIT License
24 stars 13 forks source link

plotting with AguaClara code and Matplotlib backend #135

Closed monroews closed 5 years ago

monroews commented 5 years ago

plotting using the aguaclara code base is different than how it worked in aide_design.

The command fig, ax = plt.subplots() results in a blank figure showing as a result right after that line of code.

The command plt.show() no longer produces any output.

This seems to related to a change in the matplot lib environment. See.

What backend should we be using (and teaching!) for student use as they do data analysis?

HannahSi commented 5 years ago

Hi Monroe,

From the bit of testing I did just now, it seems like the backend 'TKagg' should work. What the aguaclara package is currently using*, 'Agg', is apparently a non-GUI backend, so it does not support plt.show().

I think we can correct for this in play.py by changing our matplotlib import from

import matplotlib
matplotlib.use('agg')
import matplotlib.pyplot as plt

to:

import matplotlib.pyplot as plt
plt.switch_backend('TKAgg')

But for now, could you let me know if using the line plt.switch_backend('TKAgg') after your plt import allows your graphs to show?

monroews commented 5 years ago

I think this is a change our Atom environment.

This simple code snippet no longer works in Atom the way it used to. It creates a separate plot for each line of code and then doesn't put everything together into one figure. I think this new (and undesirable behavior) is not related to changes in the AguaClara code base.

import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(0, 2, 100)
plt.plot(x, x, label='linear')
plt.plot(x, x**2, label='quadratic')
plt.plot(x, x**3, label='cubic')

plt.xlabel('x label')
plt.ylabel('y label')
plt.title("Simple Plot")
plt.legend()
plt.show()
monroews commented 5 years ago

This problem seems to have gone away without any changes in the code. So I'm going to close this...