Jump to content

Connect Leeroopedia MCP: Equip your AI agents to search best practices, build plans, verify code, diagnose failures, and look up hyperparameter defaults.

Implementation:Mbzuai oryx Awesome LLM Post training Matplotlib Bar Chart

From Leeroopedia


Knowledge Sources
Domains Visualization, Bibliometrics
Last Updated 2026-02-08 07:30 GMT

Overview

Concrete tool for generating publication trend bar charts using matplotlib in the research trend analysis pipeline.

Description

The visualization block in future_research_data.py creates a bar chart for each research keyword using plt.bar, with years on the x-axis and paper counts on the y-axis. Charts are styled with a fixed color (#2c7fb8), 12x6 figure dimensions, labeled axes, gridlines on the y-axis, and value labels on top of each bar for precise reading. Each chart is saved as a PNG file in the results/ directory and displayed via plt.show().

Usage

This visualization runs once per keyword in the main processing loop, after the yearly publication counts have been collected. It requires a pandas DataFrame with Year and Papers Published columns.

Code Reference

Source Location

Signature

# Inline visualization block (not a standalone function)
plt.figure(figsize=(12, 6))
bars = plt.bar(df_counts['Year'], df_counts['Papers Published'], color='#2c7fb8')
plt.title(f'Publication Trend for "{keyword}" ({category})', fontsize=14, pad=20)
plt.xlabel('Year', fontsize=12)
plt.ylabel('Number of Papers', fontsize=12)
plt.xticks(years)
plt.grid(axis='y', linestyle='--', alpha=0.7)

# Add value labels on top of each bar
for bar in bars:
    height = bar.get_height()
    plt.text(bar.get_x() + bar.get_width()/2., height,
             f'{height:,}', ha='center', va='bottom')

plt.tight_layout()
figure_filename = os.path.join(output_dir, f"Publication_Trend_{keyword.replace(' ', '_')}.png")
plt.savefig(figure_filename)
plt.show()

Import

import os
import matplotlib.pyplot as plt
import pandas as pd

I/O Contract

Inputs

Name Type Required Description
df_counts pandas.DataFrame Yes DataFrame with 'Year' and 'Papers Published' columns
keyword str Yes Research keyword (used in chart title and filename)
category str Yes Category name (used in chart title)
years list[int] Yes List of years for x-axis ticks
output_dir str Yes Directory path for saving PNG files

Outputs

Name Type Description
PNG file File Bar chart image saved to results/Publication_Trend_{keyword}.png
Display Plot Chart displayed via plt.show() during execution

Usage Examples

Generate a Trend Bar Chart

import os
import matplotlib.pyplot as plt
import pandas as pd

# Sample data for one keyword
keyword = "RLHF"
category = "Reinforcement Learning"
years = [2020, 2021, 2022, 2023, 2024, 2025]
counts = [50, 120, 340, 890, 1500, 2100]
output_dir = "results"
os.makedirs(output_dir, exist_ok=True)

# Create DataFrame
df_counts = pd.DataFrame({"Year": years, "Papers Published": counts})

# Generate bar chart
plt.figure(figsize=(12, 6))
bars = plt.bar(df_counts['Year'], df_counts['Papers Published'], color='#2c7fb8')
plt.title(f'Publication Trend for "{keyword}" ({category})', fontsize=14, pad=20)
plt.xlabel('Year', fontsize=12)
plt.ylabel('Number of Papers', fontsize=12)
plt.xticks(years)
plt.grid(axis='y', linestyle='--', alpha=0.7)

for bar in bars:
    height = bar.get_height()
    plt.text(bar.get_x() + bar.get_width()/2., height,
             f'{height:,}', ha='center', va='bottom')

plt.tight_layout()
figure_filename = os.path.join(output_dir, f"Publication_Trend_{keyword.replace(' ', '_')}.png")
plt.savefig(figure_filename)
plt.show()

Related Pages

Implements Principle

Requires Environment

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment