from matplotlib import pyplot as plt
import seaborn as sns
import numpy as np
# Aesthetics
sns.set_style('ticks' )
plt.rcParams["font.family" ] = "serif" # use Serif style as default font
# Create simple data
x = ["Marco" , "Tereza" , "Robert" ]
y = [70 , 60 , 99 ] # millions of inhabitants
fig, axes = plt.subplots(1 ,2 , figsize= (10 ,4 ))
axes[0 ].bar(x,y)
axes[1 ].bar(x,y)
axes[0 ].set_ylim(50 ,100 )
axes[0 ].set_title('Truncated axis' )
axes[1 ].set_title('Complete axis' )
for ax in axes:
ax.set_ylabel("Student Grades [$\%$ scale]" )
ax.grid()
fig.savefig('../figures/truncated-bars.pdf' , bbox_inches= 'tight' )
plt.show()
fig, axes = plt.subplots(1 ,2 , figsize= (12 ,4 ))
np.random.seed(4 )
quarters = ['Q' + str (index) for index in range (1 , 5 )]
for student in x:
grades = np.linspace(70 ,90 , 4 ) + np.random.normal(0 , 5 , 4 )
axes[0 ].plot(quarters, grades, label= student)
axes[1 ].plot(quarters, grades, label= student)
axes[1 ].legend()
axes[1 ].set_ylim(0 ,100 )
axes[0 ].set_title('Truncated axis' )
axes[1 ].set_title('Complete axis' )
for ax in axes:
ax.set_ylabel("Student Grades [$\%$ scale]" )
ax.grid()
fig.savefig('../figures/truncated-lines.pdf' , bbox_inches= 'tight' )
plt.show()
Figure 1: Comparing barplots with truncated or complete Y-axis.
Figure 2: Comparing lineplots with truncated or complete Y-axis.