Understanding Quran Ayat And Surah Number Plotted

The concept is straightforward enough once you actually sit down and implement it. You take the 114 surahs of the Quran, each containing a variable number of ayahs (verses), and you map them onto a two-dimensional coordinate system. The x-axis typically represents the surah number from 1 to 114. The y-axis represents the ayah count within that particular surah, ranging from 1 up to the maximum in that chapter. What comes out is essentially a scatter plot or bar representation showing the distribution of verses across the entire text. I first encountered this when someone posted a simple Python script on a coding forum around 2019. They'd loaded a JSON file containing surah metadata and just plotted it with matplotlib. It was ugly. It worked though. Since then I've run into this topic enough times on various forums to know what actually matters in practice.

Quran Ayat And Surah Number Plotted Code Example

Here is the working code. It is not elegant. It does what it needs to do. You need a JSON source with at minimum two fields: the surah number and the ayah count per surah. I use a file I maintain locally because the various API endpoints I've tested return inconsistent field names. Some call it "ayahCount", others use "numberOfAyahs", and one called it "verse_count" which broke my parser until I figured out what was happening. Most people stop at the visual. The bar chart shows long surahs like Al-Baqarah with 286 ayahs standing out immediately next to short ones like Al-Kawthar with just 3. That is the baseline observation. Beyond that, there are structural patterns worth noting.

The longest surahs cluster in the earlier part of the Quran, which reflects the chronological reverse arrangement. The later surahs tend to be shorter. This is a well-known pattern but seeing it plotted makes it concrete. You can visually identify where the transition happens between the longer Medinan-style surahs and the shorter Meccan-style ones. I once tried overlaying a moving average line with a window of 10 surahs to smooth out the noise. It helped reveal a gradual decline in ayah count from surah 1 through roughly surah 30, then stabilized with more volatility. This is useful if you are doing any kind of comparative analysis between surah groupings.

Get the Full Details

The Quran by the Numbers: Key Statistics and Figures – Ayat Al Quran
The Quran by the Numbers: Key Statistics and Figures – Ayat Al Quran

Common Problems and Workarounds

The first problem is handling the Basmalah. Some plots include it as a separate verse in certain recitations, which throws off counts for Surah 1 and Surah 27 particularly. The count differs depending on whether you follow the Hafs or Warsh transmission. If you are reproducing this for academic purposes, specify your source. I default to the standard Uthmani script count used by most digital resources, which treats the Basmalah as a verse separator rather than a counted ayah in most cases. The second issue is data format. The JSON I referenced earlier comes from the Tanzil project. Download it directly from their GitHub repository. Do not try to scrape it from a webpage because the formatting breaks occasionally. I lost half a day once because I copied raw HTML instead of the raw JSON file. The ayah count field was missing entirely in that version. A third edge case I encountered involved Surah 9, which has no Basmalah at the start. If your code assumes every surah begins with the Basmalah and adjusts counts accordingly, Surah 9 will produce an off-by-one error in any derived calculations. My workaround was to add a conditional check: if the surah number is 1 or 27, apply the Basmalah adjustment rule. Otherwise skip it.

Better Alternatives for Certain Use Cases

Bar charts are fine for a quick overview. They are not ideal if you want to see relationships between surahs or compare structural features. For that, consider a heatmap approach where surah position is one axis and ayah position within the surah is the other. Fill cells based on some metric like word frequency or thematic markers. This takes more work but produces something actually analytically useful. If you want interactive exploration, plotly gives you hover tooltips on each bar. A static matplotlib output is fine for papers and documentation, but interactive versions are better when you are iterating. The tradeoff is file size and load time. A plotly HTML export of this data runs about 400 kilobytes compared to a 50 kilobyte PNG. For serious statistical work, skip the visualization entirely and go straight to Python's scipy or R. The plotted output is illustrative at best. The underlying distribution of ayah counts across surahs follows a roughly log-normal pattern with a long right tail. That is the actual finding if you run the descriptive statistics.

Downloading the Data Source

The JSON file used in the example above is available from the Tanzil project at tanzil.net. Look for the surah metadata export. The direct link changes occasionally so searching for "tanzil surah json" will get you there. The file is approximately 15 kilobytes uncompressed and contains every surah's number, name, revelation type, and ayah count. There are also Python packages like `quran-json` on PyPI that wrap this data and give you programmatic access without downloading files manually. I do not use them because they introduce an unnecessary dependency for what amounts to a simple dictionary lookup. One JSON file and you are done. No package management headaches. If you want the completed plot image from the code example, you can generate it yourself by running the script. Save the output path to wherever you need it. There is no single canonical version of this plot because different data sources produce slightly different results depending on how they count ayahs. Always verify against a printed mushaf if accuracy matters for your work.

qur'an surah numbers and total number of surah verses | Flickr
qur'an surah numbers and total number of surah verses | Flickr