1

So, say I have a function plot(self) within the class Pendulum that calls plot. Then I have another function plot2(self) within the same class Pendulum that also calls plot. How would I set up pyplot such that both functions would set up multiple graphs as separate subplots on the same figure?

1 Answer 1

1

Try this:

import numpy as np
import matplotlib.pyplot as plt

class Pendulum:

    def __init__(self):
        self.fig = plt.figure()

    def plot1(self):
        ax = self.fig.add_subplot(211)
        ax.plot([1,2],[3,4])

    def plot2(self):
        ax = self.fig.add_subplot(212)
        ax.plot([1,2],[4,3])

p = Pendulum()
p.plot1()
p.plot2()
plt.show()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.