Python and its libraries can produce a wide range of graphs of different types. In this section, there are a example scripts which produce a few different types, using data taken from Y3 MChem Mini-projects. These are intended to be relatively simple scripts, and give you a starting point for creating your own graphs with your own data.
To download the script and data needed to create the relevant plot, right click in the link and click "Save Link As...". Before drawing a plot, it is important to consider what type of plot is best for the data and what you are trying to communicate.
These scripts all use the matplotlib library; other Python libraries such as seaborn and plotly can also be used to produce advanced graphs.
Please contact alan.m.lewis@york.ac.uk with any questions, corrections or suggestions!
Plotting multiple sets of data is a common way to visualise similarities and differences between related datasets, such as data collected at different temperatures, or for different but similar molecules. Scatter plots can be better than line plots when the data is noisy.
scatter_multiline.py ↓ (GitHub)
The example plot on the right is created using the data below; it shows how the concentration of different amino acids changes over time when ostrich eggshell is heated at 80℃.
For more details, try the matplotlib documentation for scatter graphs.
When data has significant uncertainty in a measurement or calculation, it is important communicate both the average value of the data and the associated uncertainty. Adding error bars around each data point is the most common way to do this.
The example plot on the right is created using the data files below; it shows how the ozone concentration as emissions of VOCs from different sources vary.
For more details, try the matplotlib documentation for graphs with error bars.
A bar chart is a very simple way of conveying data. It is often used to highlight differences in average values under different conditions.
The example plot on the right is created using the data below; it shows the average yield of a certain reaction when two different bases are used.
For more details, try the matplotlib documentation for bar charts.
A box plot displays information about the distribution of a set of data, including the median value, the inter-quartile range (the range covered by the middle 50% of the data) and the extent of the outliers.
The example plot on the right is created using the same data as the bar chart (linked below as well); it shows the distribution of yields of a certain reaction when two different bases are used. Comparing this to the bar chart above, we see a graph which is takes slightly longer to read, but also contains much more information.
For more details, try the matplotlib documentation for box plots.
Histograms are used to show the distribution of continuous data, in more fine detail than a box plot would. The raw data is grouped into "bins", and the histogram shows the number of values which fall into each bin.
The example plot on the right is created using the data below; it shows the distribution of Oleic Acid content as a percentage of the total fatty acid content in a range of olive oils.
For more details, try the matplotlib documentation for histograms.
Pie charts can only be used to show proportions of a whole. If you have a large number of small contributions to the whole, it is often a good idea to group them together into larger categories, or into an "Other" category if some large contributions are also present.
The example plot on the right is created using the same data as the histogram (linked below as well); it shows the average makeup of fatty acid content in a range of olive oils.
For more details, try the matplotlib documentation for pie charts.
Contour plots allow three-dimensional data to displayed, when the data contains two independent variables (on the x- and y-axes), and a dependent variable, whose value is indicated by the choice of colour.
The example plot on the right is created using the data below; it shows the relative activity of an enzyme as a percentage of the maximum activity as a function of both temperature and pH.
For more details, try the matplotlib documentation for contour plots.
It can be helpful to create multiple graphs in one figure. This requires similar, but slightly more advanced Python syntax. This example shows two bar charts in one figure, but multiplots can be composed of any types of plot. This is also an example of a more advanced bar chart, with multiple bars associated with each value on the x axis.
The example plot on the right is created using the data files linked below; it shows the clearing and melting temperatures of organic liquid crystals with different numbers of carbon atoms in the cation, and different counter-anions.
For more details, try the matplotlib guides for creating subplots and grouped bar charts.