A simple code for plotting figure, colorbar, and cropping with python

Overview

Python Plotting Tools

This repository provides a python code to generate figures (e.g., curves and barcharts) that can be used in the paper to show the results.

Dependencies: Python 3.+, numpy, and matplotlib.

Table of Contents

Preliminary

Layout of the diagram

The following shows a simple but complete diagram.

It contains the following common components. When creating a new diagram, we will modify these components to present our data:

  • Title
  • X-Label, xtick, and, xticklabel
  • Y-Label, ytick, and, yticklabel
  • Line, Marker, Legend
  • Grid

Sample configuration file

In this code, we define the appearance of the diagram with a configuration file. Then, we can plot the diagram by simply running:

python plot_diagram.py examples/demo/simple_plot.conf

The configuration file for the above simple plot is shown below with comments.

# CONFIGURATION FILE

# Comments start with '#'; 
# Parameters start with '!';
# If a parameter contains space, please replace the space with '&' for correct parsing
# For bool type, 1 is True else False

# Plot type: ploty|plotxy|plottwins
# ploty: The input data only contains Y values, the X values are generated as [0, ..., len(Y)]
# plotxy: The input data contains both X and Y values
# plottwins: The input data only contains Y values. Plot figure with two different Y-axis
! plot_type plotxy

# Figure format: pdf|jpg|png
! format pdf

# Canvas setting, fig size in inches
# https://matplotlib.org/devdocs/gallery/subplots_axes_and_figures/figure_size_units.html
! width 7
! height 3
! dpi 220

# Line and marker setting, different lines have different colors and marker shapes
# https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.plot.html
# Example colors: 'r', 'k', 'b', 'g', 'y', 'm', 'c', 'tab:blue', 'tab:orange'
# Example markers: 'd', 'v', '1', '8', 'o', '^', '<', '>', 's', '*', 'p' 
! linewidth 1.5
! line_style -
! color tab:blue tab:orange tab:green
! markersize 4
! marker d v *

# Title and label setting 
# None indicates ignore; '&' is a placeholder for space;
# Eample font sizes: 'x-small', 'small', 'medium', 'large', 'x-large', 'xx-large', 'larger', 'smaller'
! title Simple&Plot
! title_font x-large
! xlabel x-Label
! xlabel_font x-large
! ylabel y-Label
! ylabel_font x-large

# Legend setting
# https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.legend.html
# Example legend loc: 'best', 'upper left', 'upper right', 'lower left', 'lower right'
! legend Linear Quadratic Cubic
! legend_loc upper&left
! legend_font x-large
! legend_ncol 1

# Set grid on or off, 1 for on, 0 for off
! grid_on 1

# Data configuration
# Store the data values of a curve in a file, e.g., data.txt
# If have multiple curves, just list the file names one by one
! datafile data/linear.txt data/quadratic.txt data/cubic.txt

# Specify the maximum number of points, 
! max_point_num 1000

# set whether sort the data (None|ascend|descend), all x values should be the same for different curves
! sort_data None

Examples for Plotting Curves

Plot simple curves

The main difference between the following three configuration files is the number of curves.

# Figure at the below left
python plot_diagram.py examples/curve_simple_example/ploty_single_curve.conf

# Figure at the below middle
python plot_diagram.py examples/curve_simple_example/ploty_two_curves.conf

# Figure at the below right
python plot_diagram.py examples/curve_simple_example/ploty_multi_curves.conf

Plot dots

By adding "! draw_dot 1" in the .conf, we can plot dots instead of lines.

python plot_diagram.py examples/curve_simple_example/ploty_multi_dots.conf

Plot figure with customized xticklabel

We can manually set the xticklabel in the configuration file. e.g., adding "! xticklabel 2 4 9 18 30 36 45 60 90 180 $\infty$".

python plot_diagram.py examples/curve_custom_xtick/ploty_set_xtick.conf

We can also load the xticklabel from a file by setting the path, e.g., adding "! xtick_path data/merl_name.txt". We can rotate the xticklabel if they are too long by adding "! xtick_rot 90".

python plot_diagram.py examples/curve_custom_xtick/ploty_set_rotate_xtick.conf
# Remember that we can plot dots by setting draw_dot to 1 in the configuration file

Plot figure with two different Y-axes

By setting the plot_type to plottwins, we can draw the figure with two different Y-axes. But remember that this current implementation only supports two curves, one for each Y-axis.

python plot_diagram.py examples/curve_twin_y_axis/plottwins_yaxis.conf

Plot figure with customized legends

Note that this example is a hardcode for this specific legend pattern (i.e., two curves share the same legend).

python plot_diagram.py examples/curve_custom_legend/ploty_custom_legend.conf

Examples for Plot Functions

TODO.

Examples for Plotting Barchart

Layout of the barchart

The following shows a simple barchart.


It contains the following common components. When creating a new barchart, we will modify these components to present our data:

  • Title
  • X-Label, xtick, and, xticklabel
  • Y-Label, ytick, and, yticklabel
  • Bar, Text, Legend
  • Grid

The above barchart can be generated by running:

python plot_diagram.py examples/barchart_example1/simple_barchart.conf
Configuration file for the above barchart
# CONFIGURATION FILE

# Comments start with '#'; 
# Parameters start with '!';
# If a parameter contains space, please replace the space with '&' for correct parsing
# For bool type, 1 is True else False

# Plot type: ploty|plotxy|plottwins
# ploty: The input data only contains Y values, the X values are generated as [0, ..., len(Y)]
# plotxy: The input data contains both X and Y values
# plottwins: The input data only contains Y values. Plot figure with two different Y-axis
    ! plot_type plotbar

# Figure format: pdf|jpg|png
    ! format pdf

# Canvas setting, fig size in inches
# https://matplotlib.org/devdocs/gallery/subplots_axes_and_figures/figure_size_units.html
    ! width 5.5
    ! height 3
    ! dpi 220

# Data configuration
# Store the data values of the barchart in a single file, e.g., data.txt
# Each column corresponds to a group
# The number of row equals to the number of bars in a group 
    ! datafile data/bar_data_3group.txt

# IMPORTANT: Please remember to update the color, legend, xticklabel to match the input

# Bar setting
# Opacity sets the transparency of the bar, 0 indicates solid color
# Number of color and Opacity should equal to the bar numbers
    ! bar_width 0.3
    ! color tab:blue tab:red
    ! opacity 0.4 0.4
    ! y_min 0
    ! y_max 1

# xtick and ytick setting
    ! xticklabel vs.&Method1 vs.&Method2 vs.&Method3
# ! ytick 0 0.2 0.4 0.6 0.8 1.0
# ! yticklabel 0 20% 40% 60% 80% 100%

# Text setting
    ! put_text 1
    ! text_font 18
    ! percentage 0

# Title and label setting 
# None indicates ignore; '&' is a placeholder for space;
# Eample font sizes: 'x-small', 'small', 'medium', 'large', 'x-large', 'xx-large', 'larger', 'smaller'
    ! title Title
    ! title_font x-large
    ! xlabel x-Label
    ! xlabel_font x-large
    ! ylabel y-Label
    ! ylabel_font x-large

# Legend setting
# https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.legend.html
# Example legend loc: 'best', 'upper left', 'upper right', 'lower left', 'lower right'
    ! legend Vote&Ours Vote&Others
    ! legend_loc upper&left
    ! legend_font xx-large
    ! legend_ncol 1
# You might need to tune the following bbox_to_anchor parameters to manually place the legends
    ! bbox_to_anchor -0.015 1.40

# Set grid on or off, 1 for on, 0 for off
    ! grid_on 1

Plot barchart with customized yticklabel

python plot_diagram.py examples/barchart_example1/simple_barchart_custom_ytick.conf

We set yticklabel in percentage, legend column number to 2, and show text in percentage, by adding the following to the config file.

! ytick 0 0.2 0.4 0.6 0.8 1.0
! yticklabel 0 20% 40% 60% 80% 100%
! legend_ncol 2
! percentage 1

Plot barchart with four bars in each group

python plot_diagram.py examples/barchart_example2/barchart_color.conf

Create Colorbar

We also provide a simple script to generate colorbar.

python img_tools/color_bar.py --colormap jet
python img_tools/color_bar.py --colormap jet --horizontal
python img_tools/color_bar.py --colormap viridis
python img_tools/color_bar.py --colormap viridis --horizontal

Crop Patches for Zoom-in Comparison

As it is very common to show zoom-in comparison between different methods in the paper, we provide a small image cropping scripts for this task.

By specifying the directory storing images, the desired box locations, and the colors, the following command can crop and highlight the boxes in the original images. However, you have to determine the locations of the boxes [left top bottom right] using other softwares.

python img_tools/image_cropper.py --in_dir examples/image_cropper_example/ -k '*.jpg' \
    --save_dir ROI --save_ext .jpg \
    --boxes 118 60 193 150 --boxes 371 452 431 521 --colors r g
# bash scripts/image_cropping.sh 


We can also add arrows onto the images to further highlight the differences.

python img_tools/image_cropper.py --in_dir examples/image_cropper_example/ --key '*.jpg' \
    --save_dir ROI_arrow --save_ext .jpg \
    --boxes 118 60 193 150 --boxes 371 452 431 521 --colors r g \
    --arrows 86 138 99 154 --arrows 502 412 488 393 --arrow_color r g


TODO: support selecting boxes in an interactive manner.

Owner
Guanying Chen
Guanying Chen
DrawBot lets you draw images taken from the internet on Skribbl.io, Gartic Phone and Paint

DrawBot You don't speak french? No worries, english translation is over here. C'est quoi ? DrawBot est un logiciel codé par V2F qui va prendre possess

V2F 205 Jan 01, 2023
An application that allows you to design and test your own stock trading algorithms in an attempt to beat the market.

StockBot is a Python application for designing and testing your own daily stock trading algorithms. Installation Use the

Ryan Cullen 280 Dec 19, 2022
A tool for creating Toontown-style nametags in Panda3D

Toontown-Nametag Toontown-Nametag is a tool for creating Toontown Online/Toontown Rewritten-style nametags in Panda3D. It contains a function, createN

BoggoTV 2 Dec 23, 2021
Fastest Gephi's ForceAtlas2 graph layout algorithm implemented for Python and NetworkX

ForceAtlas2 for Python A port of Gephi's Force Atlas 2 layout algorithm to Python 2 and Python 3 (with a wrapper for NetworkX and igraph). This is the

Bhargav Chippada 227 Jan 05, 2023
PyPassword is a simple follow up to PyPassphrase

PyPassword PyPassword is a simple follow up to PyPassphrase. After finishing that project it occured to me that while some may wish to use that option

Scotty 2 Jan 22, 2022
China and India Population and GDP Visualization

China and India Population and GDP Visualization Historical Population Comparison between India and China This graph shows the population data of Indi

Nicolas De Mello 10 Oct 27, 2021
Time series visualizer is a flexible extension that provides filling world map by country from real data.

Time-series-visualizer Time series visualizer is a flexible extension that provides filling world map by country from csv or json file. You can know d

Long Ng 3 Jul 09, 2021
Simple implementation of Self Organizing Maps (SOMs) with rectangular and hexagonal grid topologies

py-self-organizing-map Simple implementation of Self Organizing Maps (SOMs) with rectangular and hexagonal grid topologies. A SOM is a simple unsuperv

Jonas Grebe 1 Feb 10, 2022
ipyvizzu - Jupyter notebook integration of Vizzu

ipyvizzu - Jupyter notebook integration of Vizzu. Tutorial · Examples · Repository About The Project ipyvizzu is the Jupyter Notebook integration of V

Vizzu 729 Jan 08, 2023
Rockstar - Makes you a Rockstar C++ Programmer in 2 minutes

Rockstar Rockstar is one amazing library, which will make you a Rockstar Programmer in just 2 minutes. In last decade, people learned C++ in 21 days.

4k Jan 05, 2023
Python implementation of the Density Line Chart by Moritz & Fisher.

PyDLC - Density Line Charts with Python Python implementation of the Density Line Chart (Moritz & Fisher, 2018) to visualize large collections of time

Charles L. Bérubé 10 Jan 06, 2023
Apache Superset is a Data Visualization and Data Exploration Platform

Superset A modern, enterprise-ready business intelligence web application. Why Superset? | Supported Databases | Installation and Configuration | Rele

The Apache Software Foundation 50k Jan 06, 2023
Sparkling Pandas

SparklingPandas SparklingPandas aims to make it easy to use the distributed computing power of PySpark to scale your data analysis with Pandas. Sparkl

366 Oct 27, 2022
Create animated and pretty Pandas Dataframe or Pandas Series

Rich DataFrame Create animated and pretty Pandas Dataframe or Pandas Series, as shown below: Installation pip install rich-dataframe Usage Minimal exa

Khuyen Tran 92 Dec 26, 2022
Friday Night Funkin - converts a chart from 4/4 time to 6/8 time, or from regular to swing tempo.

Chart to swing converter As seen in https://twitter.com/i_winxd/status/1462220493558366214 A program written in python that converts a chart from 4/4

5 Dec 23, 2022
Cartopy - a cartographic python library with matplotlib support

Cartopy is a Python package designed to make drawing maps for data analysis and visualisation easy. Table of contents Overview Get in touch License an

1.2k Jan 01, 2023
Functions for easily making publication-quality figures with matplotlib.

Data-viz utils 📈 Functions for data visualization in matplotlib 📚 API Can be installed using pip install dvu and then imported with import dvu. You

Chandan Singh 16 Sep 15, 2022
A Jupyter - Leaflet.js bridge

ipyleaflet A Jupyter / Leaflet bridge enabling interactive maps in the Jupyter notebook. Usage Selecting a basemap for a leaflet map: Loading a geojso

Jupyter Widgets 1.3k Dec 27, 2022
NumPy and Pandas interface to Big Data

Blaze translates a subset of modified NumPy and Pandas-like syntax to databases and other computing systems. Blaze allows Python users a familiar inte

Blaze 3.1k Jan 01, 2023
阴阳师后台全平台(使用网易 MuMu 模拟器)辅助。支持御魂,觉醒,御灵,结界突破,秘闻副本,地域鬼王。

阴阳师后台全平台辅助 Python 版本:Python 3.8.3 模拟器:网易 MuMu | 雷电模拟器 模拟器分辨率:1024*576 显卡渲染模式:兼容(OpenGL) 兼容 Windows 系统和 MacOS 系统 思路: 利用 adb 截图后,使用 opencv 找图找色,模拟点击。使用

简讯 27 Jul 09, 2022