0 purchases
simpleplots 0.7.2
This library is created with the following idea in mind: "If, for some reason, I need to create a lot of simple linear graphs and save their images, I don't want to worry about memory leaks. It must be easy to plot a simple 2D graph and save the figure, even if it's 100 of them!"
Pure Python, lightweight, Pillow-based plotting tool, focused on efficiency and prevention of memory losses. The project is, obviously, not trying to compete with matplotlib in data analysis, but aims to satisfy a specific purpose of being able to create and save a large number of figures in the most efficient, yet accurate way.
Installation
You can simply install the library from PyPi using pip.
pip install simpleplots
Quick Snippet
An example of the basic usage. Method .save automatically closes the figure by default.
from simpleplots import Figure
fig = Figure()
fig.plot([2, 3, 4], [4, 2, 3], color='red')
fig.save('graph.png')
Performance
The data has been collected using memory_profiler module. You can find more tests here.
Usage Samples
The library also supports plotting multiple axes within one figure.
from simpleplots import Figure
# Create a figure
fig = Figure()
# Plot data
fig.plot([2, 3, 4], [1, 4.3, 6], color='red', linewidth=7)
fig.plot([1, 3.5, 7], [2, 3, 5], color='blue', linewidth=10)
# Save the image (automatically closes the figure)
fig.save('graph.png')
Plotting dates:
from simpleplots import Figure
from datetime import datetime
import numpy as np
# Create the data to be plotted
start, end = np.datetime64('2022-01-01'), np.datetime64('2022-01-20')
times = np.arange(start, end, np.timedelta64(1, 'D'))
values = np.random.randn(len(times))
# Create a figure
fig = Figure()
# Plot data
fig.plot(times, values, color='red', linewidth=7)
# Save the image (automatically closes the figure)
fig.save('graph.png')
Editing locators and formatters:
from simpleplots import Figure
from simpleplots.dates import DateFormatter, HourLocator
from datetime import datetime
import numpy as np
# Create the data to be plotted
start, end = np.datetime64('2022-01-01 01'), np.datetime64('2022-01-01 23')
times = np.arange(start, end, np.timedelta64(1, 'h'))
values = np.random.randn(len(times))
# Create a figure
fig = Figure()
# Create and assign locator
locator = HourLocator()
fig.set_major_locator(locator, axis='x')
# Create and assign formatter
formatter = DateFormatter('%H:%M', rotation=45)
fig.set_major_formatter(formatter, axis='x')
# Plot data
fig.plot(times, values, color='red', linewidth=7)
# Save the image (automatically closes the figure)
fig.save('graph.png')
Show legend and add title:
from simpleplots import Figure
# Create a figure
fig = Figure()
# Plot data
fig.plot([2, 3, 4], [1, 4.3, 6], color='red', label='line1')
fig.plot([1, 3.5, 7], [2, 3, 5], color='blue', label='line2')
# Show legend
fig.title('Some data')
fig.legend()
# Save the image (automatically closes the figure)
fig.save('graph.png')
Additional
simpleplots is a demand-driven library. In case you want to use simpleplots, but can't find a locator, formatter or functionality you need - leave a message by creating an issue.
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.