Question

I have thousands of sentences in series form (rows) . here's an example: 'After hearing his plea, the judge pardoned him.'

'The weather is quite sunny , though not as the other days.'

'Tom,Bill,Grace and tinkle went fishing,even though it was raining.'

so i want a histogram which displays the count of the number of commas in a sentence --

  1. 1comma

  2. 1 comma

  3. 3 commas.

each bar of the histogram should represent one sentence and its height should determine the number of commas. "i'll be doing it for different punctuations as well as some keywords".

i have already managed to get the count. all i need to do is display it.. thanks..

this is what i tried.. a1 contains the count of commas for each sentence. i need to plot the no of commas against each sentence

X = [i for i in range(len(a1))]

plt.bar(X,a1,width=2.5,color="blue")

an error that module object has no attribute "bar" . i imported matplotlib as plt in beginning..

Was it helpful?

Solution

Unless I am mistaken (the comments don't seem to mention this). Your problem is that you recieve the error module object has no attribute "bar". I think this is because you are doing

import matplotlib as plt
plt.bar(..

If instead you import as

import matplotlib.pyplot as plt

Then plt as a function bar() which you can use. Some more information on this can be found here.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top