Originally written on 2020-01-20. DEV's displayed publication date reflects this archive migration.
installation
$ python3 -m pip install --user matplotlib
notes
plotting a simple line graph is actually quite easy employing matplotlib. After installation,
import matplotlib.pyplot as plt(pyplot module provides many functions that generate charts and plots);declare input and output values (on x and y axis);
Before generate the plot, you can choose a built-in style for the plot:
plt.style.use('xxxx')
>>> plt.style.available
['seaborn-dark', 'seaborn-darkgrid', 'seaborn-ticks', 'fivethirtyeight', 'seaborn-whitegrid', 'classic', '_classic_test', 'fast', 'seaborn-talk', 'seaborn-dark-palette', 'seaborn-bright', 'seaborn-pastel', 'grayscale', 'seaborn-notebook', 'ggplot', 'seaborn-colorblind', 'seaborn-muted', 'seaborn', 'Solarize_Light2', 'seaborn-paper', 'bmh', 'tableau-colorblind10', 'seaborn-white', 'dark_background', 'seaborn-poster', 'seaborn-deep']
fig, ax = plt.subplots()(subplots function can generate one or more plots in the same figure, fig->the_whole_figure, ax->a_plot_in_figure);ax.axis([x_from, x_to, y_from, y_to])setting axis range-
Methods to render data:
- Plot a single line:
ax.plot(input, output, lineweight=x) - Plot dots:
ax.scatter(x, y, s=number, c='color_name'/(0.3, 0.8, 1))
- Plot a single line:
style the plot i.e. the ax, by setting its title and x/y labels, tick_params
ax.set_title("Square Numbers", fontsize=24)
ax.set_xlabel("Value", fontsize=14)
ax.set_ylabel("Square of Value", fontsize=14)
ax.tick_params(axis='both', labelsize=14)
-
plt.show()(opens matplotlib's viewer)
Top comments (0)