{"id":25076585,"url":"https://github.com/muhammedzohaib/awesome-matplotlib","last_synced_at":"2026-01-08T17:30:52.474Z","repository":{"id":225005349,"uuid":"764830413","full_name":"MuhammedZohaib/awesome-matplotlib","owner":"MuhammedZohaib","description":"A comprehensive guide for using python plotting library matplotlib which covers most of the necessary plots for data visualization.","archived":false,"fork":false,"pushed_at":"2024-02-28T19:43:43.000Z","size":5,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-16T10:02:03.332Z","etag":null,"topics":["matplotlib","matplotlib-guide","matplotlib-pyplot","matplotlib-python","matplotlib-tutorial"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MuhammedZohaib.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-02-28T19:38:58.000Z","updated_at":"2024-07-18T15:55:43.000Z","dependencies_parsed_at":null,"dependency_job_id":"6675bb0b-b23b-4808-aa2e-abcec941adaf","html_url":"https://github.com/MuhammedZohaib/awesome-matplotlib","commit_stats":null,"previous_names":["muhammedzohaib/a-beginner-s-guide-to-matplotlib","muhammedzohaib/awesome-matplotlib"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MuhammedZohaib%2Fawesome-matplotlib","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MuhammedZohaib%2Fawesome-matplotlib/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MuhammedZohaib%2Fawesome-matplotlib/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MuhammedZohaib%2Fawesome-matplotlib/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MuhammedZohaib","download_url":"https://codeload.github.com/MuhammedZohaib/awesome-matplotlib/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246117703,"owners_count":20726068,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["matplotlib","matplotlib-guide","matplotlib-pyplot","matplotlib-python","matplotlib-tutorial"],"created_at":"2025-02-07T01:46:41.748Z","updated_at":"2026-01-08T17:30:52.437Z","avatar_url":"https://github.com/MuhammedZohaib.png","language":null,"readme":"# A Beginner's Guide to Matplotlib\n\n\u003e ### **Matplotlib**\n\n```python\nimport matplotlib.pyplot as plt\nfig, ax = plt.subplots()\n\nax.plot(x,y)\nplt.show()\n\n# adding a marker to the plot'\n# visit https://matplotlib.org/stable/api/markers_api.html'\nax.plot(x, y, marker=\"o\")\n\n# changing the linestyle\nax.plot(x, y, marker=\"o\", linestyle=\"--\")\n# visit: https://matplotlib.org/stable/gallery/lines_bars_and_markers/linestyles.html\n\n# changing the line color\nax.plot(x, y, marker=\"o\", linestyle=\"--\", color = 'r')\n# setting the plot labels\nax.set_xlabel(\"This is x label\")\nax.set_ylabel(\"This is y label\")\nax.set_title(\"This is the title\")\n\n# small multiples\nfig, ax = plt.subplots(3,2)\n# this will return an array of subplots which can be indexed for plotting\n# this will insure the range on y-axis is same in all subplots\nfig, ax = plt.subplots(3,2)\n```\n\n### Plotting Time Series Data\n\n```python\nfig, ax = plt.subplots()\nax.plot(df.index, df['col'])\nax.set_xlabel(\"This is x-label\")\nax.set_ylabel(\"This is y-label\")\n# Using different y-axis\nax2 = ax.twinx()\nax2.plot(df.index, df['col_1']) # different y-axis but same x-axis\nax2.set_ylabel(\"This is y-label for 2nd plot\")\nplt.show()\n\n# we can give color to the plots as well as the labels and ticks\nax.tick_params('either x or y', color='color_name')\n```\n\n### Adding Annotations\n\n```python\nax.annotate(\"annotation text\", xy=(pd.TimeStamp(\"yyyy-mm-dd\"), 1))\n\n# moving the annotation:\nax.annotate(\"annotation text\", xy=(pd.TimeStamp(\"yyyy-mm-dd\"), 1), xytext=(pd.Timestamp(\"yyyy-mm-dd\"), -0.2))\n\n# adding arrow to connect the annotation and plot point\nax2.annotate(\"\u003e1 degree\", xy=(pd.Timestamp(\"yyyy-mm-dd\"), 1), \n            xytext=(pd.Timestamp(\"yyyy-mm-dd\"), -0.2),\n             arrowprops={\"arrowstyle\": \"-\u003e\", \"color\":\"gray\"})\n```\n\n### Bar Charts\n\n```python\n# simple bar chat\nfig, ax = plt.subplots()\nax.bar(x, y)\nplt.show()\n\n# rotating the x-tick labels by 90 degree\nax.set_xticklabels(column, rotation=90)\n\n# creating a stacked bar-chart\nax.bar(x1, y)\nax.bar(x2, y, bottom=x1)\nax.bar(x3, y, bottom=x1+x2)\n\n# adding legends\nax.legend()\n\n# showing plot\nax.show()\n```\n\n### Histograms\n\n```python\nfig, ax = plt.sublplots()\nax.hist(dataframe['column'])\nplt.show()\n\nax.hist(dataframe['column'], label=\"label for this histogram\", bins=\"number of bins\")\n# we can also provide a list of bins in bins parameter\nax.hist(dataframe['column'], bins=[20, 40, 60, 80, 100])\n\n# sometimes if we plot multiple variables in a single plot our plot can be\n# overlapping so we can change the histogram type so it can be hollow and\n# visible\nax.hist(dataframe['column'], bins=[20, 40, 60, 80, 100], histtype=\"Step\")\n```\n\n### Statistical Plotting\n\n```python\n# Error Plot -- 1\nfig, ax = plt.subplots()\n\nax.bar(\"Rowing\", mens_rowing['Height'].mean(), yerr=mens_rowing['Height'].std())\nax.bar(\"Gymnastics\", mens_gymnastics['Height'].mean(), yerr=mens_gymnastics['Height'].std())\nax.set_ylabel(\"Height (cm)\")\nplt.show()\n\n# Error Plot -- 2\nfig, ax = plt.subplots()\nax.errorbar(seattle_weather['MONTH'], seattle_weather['MLY-TAVG-NORMAL'], yerr=seattle_weather['MLY-TAVG-STDDEV'])\nax.errorbar(austin_weather['MONTH'], austin_weather['MLY-TAVG-NORMAL'], yerr=austin_weather['MLY-TAVG-STDDEV'])\nax.set_ylabel(\"Temperature (Fahrenheit)\")\nplt.show()\n\n# Error Plot -- 3 (Box Plot)\nfig, ax = plt.subplots()\nax.boxplot([mens_rowing['Height'], mens_gymnastics['Height']])\nax.set_xticklabels([\"Rowing\", \"Gymnastics\"])\nax.set_ylabel(\"Height (cm)\")\nplt.show()\n```\n\n### Scatter Plot\n\n```python\nfig, ax = plt.subplots()\nax.scatter(climate_change['co2'], climate_change['relative_temp'])\nax.set_xlabel(\"CO2 (ppm)\")\nax.set_ylabel(\"Relative temperature (C)\")\nplt.show()\n\n# giving time index to scatter plot as c param\nfig, ax = plt.subplots()\nax.scatter(climate_change['co2'], climate_change['relative_temp'], c=climate_change.index)\nax.set_xlabel(\"CO2 (ppm)\")\nax.set_ylabel(\"Relative temperature (C)\")\nplt.show()\n```\n\n### Changing Plot Style in Matplotlib\n\n```python\nplt.style.use(\"ggplot\")\nplt.style.use(\"default\")\nplt.style.use(\"bmh\")\nplt.style.use(\"seaborn-colorblind\")\nplt.style.use(\"tableau-colorblind10\")\nplt.style.use(\"grayscale\")\nplt.style.use(\"Solarize_Light2\")\n```\n\n### Saving Matplotlib Plots\n\n```python\nfig.savefig(\"Name_of_plot.png\")\nfig.savefig(\"Name_of_plot.jpg\")\nfig.savefig(\"Name_of_plot.jpg\", quality=50) # 50% quality\nfig.savefig(\"Name_of_plot.svg\")\nfig.savefig(\"Name_of_plot.png\", dpi=300)\n\n# controlling the size of the figure\nfig.set_size_inches([5,3]) # [width, height]\n\n\n# plot pipeline example:\nfig, ax = plt.subplots()\nfor sport in sports:\n  sport_df = summer_2016_medals[summer_2016_medals['Sport'] == sport]\n  ax.bar(sport, sport_df[\"Weight\"].mean(), yerr=sport_df[\"Weight\"].std())\n\nax.set_ylabel(\"Weight\")\nax.set_xticklabels(sports, rotation=90)\nfig.savefig(\"sports_weights.png\")\n```\n\n---\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmuhammedzohaib%2Fawesome-matplotlib","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmuhammedzohaib%2Fawesome-matplotlib","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmuhammedzohaib%2Fawesome-matplotlib/lists"}