Generate the legend and XTickLabel automatically