
Figure 1:Chart of all imports and exports to and from England Playfair’s Atlas 1786.
import pandas as pd
import numpy as np
import matplotlib.pyplot as pltdata = {
'Year': ['1700', '1710', '1720', '1730', '1740', '1750', '1760', '1770', '1771', '1772', '1773', '1774', '1775', '1776', '1777', '1778', '1779', '1780', '1781', '1782', '1783', '1784', '1785'],
'Imports': [4.5, 4.85, 5.35, 8.5, 8.5, 8.2, 10.2, 11.7, 12.7, 13.25, 11.3, 13.3, 13.6, 11.5, 11.85, 10.2, 10.6, 10.8, 11.8, np.nan, np.nan, np.nan, np.nan],
'Exports':[6.2, 7.0, 8.7, 11.0, 12.0, 12.6, 14.3, 16.3, 17.2, 16.2, 14.8, 15.8, 15.3, 13.5, 12.65, 11.7, 12.6, 12.5, 10.5, np.nan, np.nan, np.nan, np.nan]
}
df = pd.DataFrame(data)
print(df)
df.to_csv('Playfair_ImpExp_Eng_1786_final.csv', index=True)import matplotlib.pyplot as plt
plt.figure(figsize=(12, 6))
plt.plot(df['Year'], df['Imports'], label='Imports', marker='o')
plt.plot(df['Year'], df['Exports'], label='Exports', marker='o')
plt.xlabel('Year')
plt.ylabel('Value')
plt.title('Imports and Exports Over Time')
plt.xticks(rotation=45)
plt.legend()
plt.grid(True)
plt.tight_layout()
plt.show()import matplotlib.pyplot as plt
# Convert 'Year' to integers
df['Year'] = df['Year'].astype(int)
plt.figure(figsize=(12, 6))
plt.plot(df['Year'], df['Imports'], label='Imports', marker='o')
plt.plot(df['Year'], df['Exports'], label='Exports', marker='o')
plt.xlabel('Year')
plt.ylabel('Value')
plt.title('Imports and Exports Over Time')
plt.legend()
plt.grid(True)
plt.tight_layout()
plt.show()# 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()
%matplotlib notebook
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
import numpy as np
fig, ax = plt.subplots(figsize=(12, 6))
x = df_agg['Year']
y_imports = df_agg['Imports']
y_exports = df_agg['Exports']
line_imports, = ax.plot([], [], label='Imports', marker='o')
line_exports, = ax.plot([], [], label='Exports', marker='o')
ax.set_xlim(min(x), max(x))
ax.set_ylim(min(min(y_imports), min(y_exports)) * 0.9, max(max(y_imports), max(y_exports)) * 1.1)
ax.set_xlabel('Year')
ax.set_ylabel('Value')
ax.set_title('Imports and Exports Over Time (Animated)')
ax.legend()
ax.grid(True)
def update(frame):
line_imports.set_data(x[:frame], y_imports[:frame])
line_exports.set_data(x[:frame], y_exports[:frame])
return line_imports, line_exports,
ani = FuncAnimation(fig, update, frames=len(x) + 1, interval=1000, blit=True, repeat=False)
ani
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()