Skip to main content

A visualization tool for line plan

Project description

LinePlanVisualization

A visualization tool for line plan based on matplotlib.
According to our specified data structure, your line plan can be visualized easily, and also we provide a lot of parameters to adjust the appearance.

Install

pip install line_plan_visualization

Usage

This tool consists of three main classes: PhysicalRailway, Lines and LinePlan.

PhysicalRailway

This class represents the physical railway to visualize.
When creating an instance of PhysicalRailway, the fisrt parameter you need to pass in should be str type representing the name of the railway. The second parameter should be dict type which the keys are str type representing the names of stations and the values are str type representing stations' levels. The level should be one of "high", "medium" and "low". The order of the stations in the dictionary is the order of the visualization.

# an instance of class PhysicalRailway 
example_pr = PhysicalRailWay("Beijing-Shanghai High-Speed Raiway",  # railway name
                             {"BJN": "high",  # stations names and levels in order
                              "LF": "low",
                              "TJN": "high",
                              "CZX": "medium",
                              "DZD": "medium",
                              "JNX": "high",
                              "TA": "medium",
                              "QFD": "medium",
                              "TZD": "low",
                              "ZZ": "low",
                              "XZD": "high",
                              "SZD": "low",
                              "BBN": "medium",
                              "DY": "low",
                              "CZ": "low",
                              "NJN": "high",
                              "ZJN": "medium",
                              "DYB": "low",
                              "CZB": "medium",
                              "WXD": "medium",
                              "SZB": "medium",
                              "KSN": "medium",
                              "SHHQ": "high"})

Lines

This class represents the train lines operating on the physical railway.
When creating an instance of Lines, the only parameter you need to pass in should be dict type which the keys are int type representing the IDs of lines(Sequentiality is not enforced) and the values are list type only containing 0 and 1 for no stop and stop at the station corresponding to the physical railway.

# 50 lines are randomly generated and lineIDs do not have to start at 0 or are ordered
lines = {}
for idx in range(25):
    lines[idx] = [random.randint(0, 1) for _ in range(len(example_pr))]  # len(example_pr) returns the num of stations

# an instance of class Lines
example_lines = Lines(lines)

LinePlan

This class combines PyhsicalRailway and Lines. When creating an instance of LinePlan, the only two parameters you need to pass in are an instance of PhysicalRailway and an instance of Line.

# an instance of class LinePlan
example_lp = LinePlan(example_pr, example_lines)

Now the line plan can be visualized by calling the function draw.

example_lp.draw()

However, the default appearance parameters may not be appropriate for your line plan, you can also pass in some custom parameters. See documentation of function draw for details. Overall, they are similar to the syntax and usage of matplotlib.

example_lp.draw(figsize=(23, 25),
                lines_color='blue')

Make sure that the function show is called after the function save, otherwise your saved image will be blank(For some unknown reasons, the saved image is the real one, the displayed image are indicative only, if you reckon the displayed image is ugly, you may wish to take a look at the saved image).

example_lp.save("fig\\testimage.png")
example_lp.show()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

line_plan_visualization-0.0.6.tar.gz (8.7 kB view hashes)

Uploaded Source

Built Distribution

line_plan_visualization-0.0.6-py3-none-any.whl (9.1 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page