Graphics¶
Learning objectives
- Make a first scatter plot
- Rehearse running a script that uses an import
- Rehearse that graphics need X-forwarding
For teachers
Teaching goals are:
- Learners hear about matplotlib
- Learners may find out again that X-forwarding is important
- Learners again have gotten 'stuff to work'
Lesson plan:
- 5 mins: prior knowledge
- 5 mins: presentation
- 15 mins: challenge
- 5 mins: feedback
Prior:
- What is meant with a plotting library?
- What is meant with a plotting package/module?
- Can you name a Python plotting package?
Overview¶
Sometimes one wants to make a plot, such like a scatterplot or barchart. Matplotlib is a popular Python package to make plots. Here we experience how easy/hard it is to use Matplotlib on Rackham.
flowchart TD
python[[Python]]
%% Give a white background to all nodes, instead of a transparent one
classDef node fill:#fff,color:#000,stroke:#000
subgraph sub_programming_language[Programming language]
interpreted_language[Interpreted language]
programming_language[Programming language]
scripting_language[Scripting language]
interpreter[Interpreter]
scripts[Scripts]
text_files[Text files]
end
style sub_programming_language fill:#ccf,color:#000,stroke:#fcc
subgraph sub_programming_terms[Programming terms]
user_input[User input]
file_io[File I/O]
command_line_arguments[Command-line arguments]
variables[Variables]
operators[Operators]
%% functions[Functions]
python_packages[Python packages]
graphics[Graphics]
end
style sub_programming_terms fill:#cfc,color:#000,stroke:#fcc
subgraph sub_uppmax[UPPMAX]
uppmax[UPPMAX]
uppmax_modules[UPPMAX modules]
uppmax_clusters[UPPMAX clusters]
text_editors[Text editors]
x_forwarding[X-forwarding]
remote_desktop[Remote desktop]
end
style sub_uppmax fill:#fcc,color:#000,stroke:#fcc
python --> |is a| programming_language
python --> |is a| interpreted_language
python --> |is a| scripting_language
programming_language --> |uses| text_files
interpreted_language --> |has a| interpreter
scripting_language --> |is|interpreted_language
scripting_language --> |runs| scripts
scripts --> |are| text_files
scripts --> |can use| command_line_arguments
python --> |has| python_packages
python --> |has| variables
%%python --> |has| functions
python --> |has| operators
%%functions --> |use| variables
operators --> |work on| variables
python_packages --> |allow| graphics
python_packages --> |allow to use| user_input
python_packages --> |allow to do| file_io
python_packages --> |allow to use| command_line_arguments
uppmax --> |has| uppmax_clusters
uppmax_clusters --> |have| uppmax_modules
uppmax_clusters --> |have| text_editors
uppmax_clusters --> |allow| x_forwarding
uppmax_clusters --> |has| remote_desktop
uppmax_modules --> |allow the use of| python_packages
uppmax_modules --> |allow the use of| interpreter
text_editors --> |work on|text_files
x_forwarding --> |allows|graphics
remote_desktop --> |allows|graphics
variables ~~~ uppmax
Exercises¶
See the exercise procedure here.
Exercise 1: Use matplotlib to show a plot¶
Learning objectives
- Make a first scatter plot
- Rehearse running a script that uses an import
- Rehearse that graphics need X-forwarding
Read matplotlib's 'Pyplot tutorial' here.
Copy-paste the first script on that page to a script and get it to work. Do you expect this to be easy?