Home > Blockchain >  Graphing Multiple Graphs on One Graph
Graphing Multiple Graphs on One Graph

Time:11-25

In python, I have the following function for creating the Mendenhall's Characteristic Curves of Composition

def mendenhall(toks):
  dist = nltk.FreqDist([len(w) for w in toks])
  x = sorted(dist.keys())
  y = [dist[i] for i in x]
  return x, y

Then I created the following graphs using it

x,y = mendenhall((nltk.corpus.brown.words(categories='romance')))
plt.plot(x,y)

and

x,y = mendenhall((nltk.corpus.brown.words(categories='mystery')))
plt.plot(x,y)

but is there a way to put these two on a graph together, or do they have to be seperate?

CodePudding user response:

Here is an existence proof that what I said works:

import matplotlib.pyplot as plt

x = [1,2,3,4,5]
y1 = [6,7,8,9,10]
y2 = [7,6,5,4,3]

plt.plot(x,y1)
plt.plot(x,y2)
plt.show()

So, in your case:

x,y = mendenhall((nltk.corpus.brown.words(categories='romance')))
plt.plot(x,y)
x,y = mendenhall((nltk.corpus.brown.words(categories='mystery')))
plt.plot(x,y)
plt.show()
  • Related