Skip to article frontmatterSkip to article content

Pontos importantes:

Divisoes
   as diferentes legendas nos anos
   a intensificacao das linhas a partir de 1770
  
Linhas 
   linhas mais largas
   cores
   labels nas linhas 
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
df = pd.read_csv('Playfair_ImpExp_Eng_1786_final.csv')
print(df.head(10))
# Convert Year to int
df['Year'] = df['Year'].astype(int)

# Group by Year and average Imports and Exports for duplicates
df_agg = df.groupby('Year').mean().reset_index()

# Plot aggregated data
plt.figure(figsize=(12, 6))
plt.plot(df_agg['Year'], df_agg['Imports'], label='Imports', marker='o')
plt.plot(df_agg['Year'], df_agg['Exports'], label='Exports', marker='o')

plt.xlabel('Year')
plt.ylabel('Value')
plt.title('Imports and Exports Over Time (Aggregated)')
plt.legend()
plt.grid(True)
plt.tight_layout()
plt.show()
plt.figure(figsize=(12, 6))

# Plot Imports as yellow line
plt.plot(df['Year'], df['Imports'], color='yellow', label='Imports', marker='o', linewidth=4)

# Plot Exports as red line
plt.plot(df['Year'], df['Exports'], color='#FF4C6D', label='Exports', marker='o', linewidth=4)

# Fill the area between Imports and Exports lines with bright blue
plt.fill_between(df['Year'], df['Imports'], df['Exports'], color='deepskyblue', alpha=0.2)

plt.xlabel('Year')
plt.ylabel('Millions of Pounds')
plt.title('Chart of all the Imports and Exports to and from England From the Year 1700 to 1782 by W. Playfair')
plt.legend()
plt.grid(True)
plt.tight_layout()
plt.show()
plt.figure(figsize=(12, 6))

plt.plot(df['Year'], df['Imports'], color='yellow', label='Imports', marker='o', linewidth=2)
plt.plot(df['Year'], df['Exports'], color='#FF4C6D', label='Exports', marker='o', linewidth=2)
plt.fill_between(df['Year'], df['Imports'], df['Exports'], color='deepskyblue', alpha=0.8)

plt.xlabel('Year')
plt.ylabel('Value')
plt.title('Imports and Exports with Fine-Grained Lines between 1770 and 1782')

# Set major ticks as usual (or with a wider interval)
major_years = np.arange(df['Year'].min(), df['Year'].max() + 1, 10)

# Set minor ticks for each year between 1770 and 1785
minor_years = np.arange(1770, 1786)

ax = plt.gca()
ax.set_xticks(major_years)
ax.set_xticks(minor_years, minor=True)

# Format major ticks with labels
ax.set_xticklabels(major_years, rotation=45)

# Optionally, hide labels on minor ticks
ax.tick_params(axis='x', which='minor', length=5, color='grey')
plt.figure(figsize=(12, 6))

plt.plot(df['Year'], df['Imports'], color='yellow', label='Imports', marker='o', linewidth=2)
plt.plot(df['Year'], df['Exports'], color='#FF4C6D', label='Exports', marker='o', linewidth=2)
plt.fill_between(df['Year'], df['Imports'], df['Exports'], color='deepskyblue', alpha=0.8)

plt.xlabel('Year')
plt.ylabel('Value')
plt.title('Imports and Exports with Complete Grid Lines')

# Set x-ticks at all data points (making sure all year values are present)
ax = plt.gca()
ax.set_xticks(df['Year'])
ax.set_xticklabels(df['Year'], rotation=45)

# Enable grid lines on all x-tick positions
ax.grid(which='both', axis='x', linestyle='--', color='grey', alpha=0.5)

# Enable grid lines on all y positions (treat y-axis similarly)
ax.grid(which='both', axis='y', linestyle='--', color='grey', alpha=0.5)

plt.tight_layout()
plt.legend()
plt.show()
plt.figure(figsize=(12, 6))

plt.plot(df['Year'], df['Imports'], color='yellow', label='Imports', marker='o', linewidth=2)
plt.plot(df['Year'], df['Exports'], color='#FF4C6D', label='Exports', marker='o', linewidth=2)
plt.fill_between(df['Year'], df['Imports'], df['Exports'], color='deepskyblue', alpha=0.8)

plt.xlabel('Year')
plt.ylabel('Value')
plt.title('Imports and Exports with Detailed Grid and Selective Labels')

ax = plt.gca()

# Set x-ticks at all data points (all years)
ax.set_xticks(df['Year'])

# Create all labels as empty first
labels = ['' for _ in df['Year']]

# Set labels only for specific years
label_years = [1770, 1775, 1780, 1785]
for i, year in enumerate(df['Year']):
    if year in label_years:
        labels[i] = str(year)

ax.set_xticklabels(labels, rotation=45)

# Enable grid lines at all ticks on x and y axis
ax.grid(which='both', axis='x', linestyle='--', color='grey', alpha=0.5)
ax.grid(which='both', axis='y', linestyle='--', color='grey', alpha=0.5)

plt.tight_layout()
plt.legend()
plt.show()
plt.figure(figsize=(18, 9))

plt.plot(df['Year'], df['Imports'], color='yellow', label='Imports', marker='o', linewidth=4)
plt.plot(df['Year'], df['Exports'], color='#FF4C6D', label='Exports', marker='o', linewidth=4)
plt.fill_between(df['Year'], df['Imports'], df['Exports'], color='deepskyblue', alpha=0.2)

plt.xlabel('The Divisions at the bottom express YEARS & those o the Righthand MILLIONS of Pounds')
plt.ylabel('Millions in Pounds')
plt.title('Chart of all the Imports and Exports to and from England From the Year 1700 to 1782 by W. Playfair')

ax = plt.gca()

years = df['Year'].values
labels = []

# Prepare labels: show all years from 1700 to 1770, then selective labels after 1770
for year in years:
    if year <= 1770:
        labels.append(str(year))
    elif year in [1770, 1775, 1780, 1785]:
        labels.append(str(year))
    else:
        labels.append('')  # Hide intermediate labels after 1770 except the selected ones

ax.set_xticks(years)
ax.set_xticklabels(labels, rotation=45)

# Enable grid lines on all major ticks
ax.grid(which='both', axis='x', linestyle='--', color='grey', alpha=0.5)
ax.grid(which='both', axis='y', linestyle='--', color='grey', alpha=0.5)

plt.tight_layout()
plt.legend()
plt.show()
import matplotlib.pyplot as plt

plt.figure(figsize=(18, 9))

plt.plot(df['Year'], df['Imports'], color='yellow', label='Imports', marker='o', linewidth=4)
plt.plot(df['Year'], df['Exports'], color='#FF4C6D', label='Exports', marker='o', linewidth=4)
plt.fill_between(df['Year'], df['Imports'], df['Exports'], color='deepskyblue', alpha=0.2)

plt.xlabel('The Divisions at the bottom express YEARS & those o the Righthand MILLIONS of Pounds')
plt.ylabel('Millions in Pounds')
plt.title('Chart of all the Imports and Exports to and from England From the Year 1700 to 1782 by W. Playfair')

ax = plt.gca()

years = df['Year'].values
labels = []

# Prepare labels: show all years from 1700 to 1770, then selective labels after 1770
for year in years:
    if year <= 1770:
        labels.append(str(year))
    elif year in [1770, 1775, 1780, 1785]:
        labels.append(str(year))
    else:
        labels.append('')  # Hide intermediate labels after 1770 except the selected ones

ax.set_xticks(years)
ax.set_xticklabels(labels, rotation=45)

# Enable grid lines on all major ticks
ax.grid(which='both', axis='x', linestyle='--', color='grey', alpha=0.5)
ax.grid(which='both', axis='y', linestyle='--', color='grey', alpha=0.5)

# Move y-axis labels and ticks to right side
ax.yaxis.tick_right()
ax.yaxis.set_label_position("right")
ax.yaxis.label.set_rotation(270)
ax.tick_params(axis='y', which='both', labelleft=False, labelright=True)

plt.tight_layout()
plt.legend()
plt.show()
import matplotlib.pyplot as plt

plt.figure(figsize=(18, 9))

plt.plot(df['Year'], df['Imports'], color='yellow', label='Imports', marker='o', linewidth=4)
plt.plot(df['Year'], df['Exports'], color='#FF4C6D', label='Exports', marker='o', linewidth=4)
plt.fill_between(df['Year'], df['Imports'], df['Exports'], color='deepskyblue', alpha=0.2)

font_family = 'Georgia'  # Change to your preferred font family
label_fontsize = 20
tick_fontsize = 14

plt.xlabel('The Divisions at the bottom express YEARS & those on the Righthand MILLIONS of Pounds',
           fontsize=label_fontsize, fontname=font_family)
plt.ylabel('Millions in Pounds',
           fontsize=label_fontsize, fontname=font_family)
plt.title('Chart of all the Imports and Exports to and from England From the Year 1700 to 1782 by W. Playfair',
          fontsize=18, fontname=font_family)

ax = plt.gca()

years = df['Year'].values
labels = []

# Prepare labels: show all years from 1700 to 1770, then selective labels after 1770
for year in years:
    if year <= 1770:
        labels.append(str(year))
    elif year in [1770, 1775, 1780, 1785]:
        labels.append(str(year))
    else:
        labels.append('')  # Hide intermediate labels after 1770 except the selected ones

ax.set_xticks(years)
ax.set_xticklabels(labels, rotation=45, fontsize=tick_fontsize, fontname=font_family)

# Enable grid lines on all major ticks
ax.grid(which='both', axis='x', linestyle='--', color='grey', alpha=0.5)
ax.grid(which='both', axis='y', linestyle='--', color='grey', alpha=0.5)

# Move y-axis labels and ticks to right side
ax.yaxis.tick_right()
ax.yaxis.set_label_position("right")
ax.yaxis.label.set_rotation(270)
ax.tick_params(axis='y', which='both', labelleft=False, labelright=True, labelsize=tick_fontsize)

# Set y tick label font name
for tick in ax.yaxis.get_ticklabels():
    tick.set_fontname(font_family)

plt.tight_layout()
plt.legend()
plt.show()
import matplotlib.pyplot as plt

plt.figure(figsize=(18, 9))

plt.plot(df['Year'], df['Imports'], color='yellow', label='Imports', marker='o', linewidth=4)
plt.plot(df['Year'], df['Exports'], color='#FF4C6D', label='Exports', marker='o', linewidth=4)
plt.fill_between(df['Year'], df['Imports'], df['Exports'], color='deepskyblue', alpha=0.2)

font_family = 'Georgia'  # Change to your preferred font family
label_fontsize = 16
tick_fontsize = 14

plt.xlabel('The Divisions at the bottom express YEARS & those on the Righthand MILLIONS of Pounds',
           fontsize=label_fontsize, fontname=font_family, labelpad=20)  # Increased padding here
plt.ylabel('Millions in Pounds',
           fontsize=label_fontsize, fontname=font_family, labelpad=30)  # Increased padding here
plt.title('Chart of all the Imports and Exports to and from England From the Year 1700 to 1782 by W. Playfair',
          fontsize=24, fontname=font_family)  # Larger title font size

ax = plt.gca()

years = df['Year'].values
labels = []

# Prepare labels: show all years from 1700 to 1770, then selective labels after 1770
for year in years:
    if year <= 1770:
        labels.append(str(year))
    elif year in [1770, 1775, 1780, 1785]:
        labels.append(str(year))
    else:
        labels.append('')  # Hide intermediate labels after 1770 except the selected ones

ax.set_xticks(years)
ax.set_xticklabels(labels, rotation=45, fontsize=tick_fontsize, fontname=font_family)

# Enable grid lines on all major ticks
ax.grid(which='both', axis='x', linestyle='--', color='grey', alpha=0.5)
ax.grid(which='both', axis='y', linestyle='--', color='grey', alpha=0.5)

# Move y-axis labels and ticks to right side
ax.yaxis.tick_right()
ax.yaxis.set_label_position("right")
ax.yaxis.label.set_rotation(270)
ax.tick_params(axis='y', which='both', labelleft=False, labelright=True, labelsize=tick_fontsize, pad=10)  # Increased tick padding
ax.tick_params(axis='x', which='both', labelsize=tick_fontsize, pad=10)  # Increased tick padding

# Set y tick label font name
for tick in ax.yaxis.get_ticklabels():
    tick.set_fontname(font_family)

plt.tight_layout()
plt.legend()

plt.savefig('Playfair_ImpExp_Chart.png', dpi=300, bbox_inches='tight')  # Save the plot as a PNG file

plt.show()