kopia lustrzana https://github.com/sepandhaghighi/samila
Marker Added (#159)
* add : `Marker` enum added. (#156) * add : `marker` parameter added. (#156) * log : changes logged. (#156) * add : RANDOM marker added. * change : minor change in docstring. * add : `Marker` added to `__init__`. * update : documents updated. * test : tests added. * edit : minor bugs fixed in tests. * fix : minor typo fixed in demo.pull/160/head
rodzic
daeafed59f
commit
27317de6c8
|
@ -5,7 +5,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
|
|||
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## [Unreleased]
|
||||
### Added
|
||||
- `Marker` enum
|
||||
### Changed
|
||||
- `marker` parameter added to `plot` method
|
||||
- Test system modified
|
||||
## [0.9] - 2022-09-28
|
||||
### Added
|
||||
|
|
15
README.md
15
README.md
|
@ -156,6 +156,21 @@ Samila is a generative art generator written in Python, Samila let's you create
|
|||
* Supported projections : `RECTILINEAR`, `POLAR`, `AITOFF`, `HAMMER`, `LAMBERT`, `MOLLWEIDE` and `RANDOM`
|
||||
* Default projection is `RECTILINEAR`
|
||||
|
||||
### Marker
|
||||
```pycon
|
||||
>>> from samila import Marker
|
||||
>>> g = GenerativeImage(f1, f2)
|
||||
>>> g.generate()
|
||||
>>> g.plot(marker=Marker.CIRCLE, spot_size=10)
|
||||
>>> g.seed
|
||||
448742
|
||||
>>> plt.show()
|
||||
```
|
||||
<img src="https://github.com/sepandhaghighi/samila/raw/master/otherfiles/images/9.png">
|
||||
|
||||
* Supported markers : `POINT`, `PIXEL`, `CIRCLE`, `TRIANGLE_DOWN`, `TRIANGLE_UP`, `TRIANGLE_LEFT`, `TRIANGLE_RIGHT`, `TRI_DOWN`, `TRI_UP`, `TRI_LEFT`, `TRI_RIGHT`, `OCTAGON`, `SQUARE`, `PENTAGON`, `PLUS`, `PLUS_FILLED`, `STAR`, `HEXAGON_VERTICAL`, `HEXAGON_HORIZONTAL`, `X`, `X_FILLED`, `DIAMOND`, `DIAMON_THIN`, `VLINE`, `HLINE` and `RANDOM`
|
||||
* Default marker is `POINT`
|
||||
|
||||
### Range
|
||||
```pycon
|
||||
>>> g = GenerativeImage(f1, f2)
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
"import matplotlib.pyplot as plt\n",
|
||||
"import random\n",
|
||||
"import math\n",
|
||||
"from samila import GenerativeImage, Projection"
|
||||
"from samila import GenerativeImage, Projection, Marker"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
@ -107,6 +107,32 @@
|
|||
" plt.close()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Marker\n",
|
||||
"We can use the `marker` attribute to change the plotting marker.\n",
|
||||
"\n",
|
||||
"The available markers are `POINT`, `PIXEL`, `CIRCLE`, `TRIANGLE_DOWN`, `TRIANGLE_UP`, `TRIANGLE_LEFT`, `TRIANGLE_RIGHT`, `TRI_DOWN`, `TRI_UP`, `TRI_LEFT`, `TRI_RIGHT`, `OCTAGON`, `SQUARE`, `PENTAGON`, `PLUS`, `PLUS_FILLED`, `STAR`, `HEXAGON_VERTICAL`, `HEXAGON_HORIZONTAL`, `X`, `X_FILLED`, `DIAMOND`, `DIAMON_THIN`, `VLINE`, `HLINE` and `RANDOM`."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"g2 = GenerativeImage(f1, f2)\n",
|
||||
"g2.generate()\n",
|
||||
"\n",
|
||||
"for m in list(Marker):\n",
|
||||
" print(m)\n",
|
||||
" g2.plot(marker=m, spot_size=100)\n",
|
||||
" plt.show()\n",
|
||||
" plt.close()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
|
@ -367,7 +393,7 @@
|
|||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3",
|
||||
"display_name": "Python 3.8.10 64-bit",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
|
@ -381,7 +407,7 @@
|
|||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.5.2"
|
||||
"version": "3.8.10"
|
||||
},
|
||||
"toc": {
|
||||
"base_numbering": 1,
|
||||
|
@ -403,7 +429,7 @@
|
|||
},
|
||||
"vscode": {
|
||||
"interpreter": {
|
||||
"hash": "e7370f93d1d0cde622a1f8e1c04877d8463912d04d973331ad4851f04de6915a"
|
||||
"hash": "31f2aee4e71d21fbe5cf8b01ff0e069b9275f58929596ceb00d14d90e3e16cd6"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
Plik binarny nie jest wyświetlany.
Po Szerokość: | Wysokość: | Rozmiar: 169 KiB |
|
@ -1,6 +1,6 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
"""Samila modules."""
|
||||
from .genimage import GenerativeImage
|
||||
from .params import Projection, VALID_COLORS, SAMILA_VERSION
|
||||
from .params import Projection, Marker, VALID_COLORS, SAMILA_VERSION
|
||||
from .errors import samilaDataError, samilaGenerateError
|
||||
__version__ = SAMILA_VERSION
|
||||
|
|
|
@ -10,10 +10,10 @@ import random
|
|||
import matplotlib
|
||||
from matplotlib import cm
|
||||
from matplotlib.colors import ListedColormap
|
||||
from .params import DEFAULT_START, DEFAULT_STOP, DEFAULT_STEP, DEFAULT_COLOR, DEFAULT_IMAGE_SIZE, DEFAULT_DEPTH
|
||||
from .params import DEFAULT_MARKER, DEFAULT_START, DEFAULT_STOP, DEFAULT_STEP, DEFAULT_COLOR, DEFAULT_IMAGE_SIZE, DEFAULT_DEPTH
|
||||
from .params import DEFAULT_CMAP, DEFAULT_CMAP_RANGE
|
||||
from .params import DEFAULT_BACKGROUND_COLOR, DEFAULT_SPOT_SIZE, DEFAULT_PROJECTION, DEFAULT_ALPHA, DEFAULT_LINEWIDTH
|
||||
from .params import Projection, VALID_COLORS, HEX_COLOR_PATTERN, NFT_STORAGE_API, NFT_STORAGE_LINK, OVERVIEW
|
||||
from .params import Projection, Marker, VALID_COLORS, HEX_COLOR_PATTERN, NFT_STORAGE_API, NFT_STORAGE_LINK, OVERVIEW
|
||||
from .params import DATA_TYPE_ERROR, DATA_FORMAT_ERROR, CONFIG_TYPE_ERROR, CONFIG_FORMAT_ERROR, PLOT_DATA_ERROR, CONFIG_NO_STR_FUNCTION_ERROR
|
||||
from .params import NO_FIG_ERROR_MESSAGE, FIG_SAVE_SUCCESS_MESSAGE, NFT_STORAGE_SUCCESS_MESSAGE, SAVE_NO_DATA_ERROR
|
||||
from .params import INVALID_COLOR_TYPE_ERROR, COLOR_SIZE_ERROR
|
||||
|
@ -257,6 +257,24 @@ def filter_projection(projection):
|
|||
return None
|
||||
|
||||
|
||||
def filter_marker(marker):
|
||||
"""
|
||||
Filter given marker.
|
||||
|
||||
:param marker: given marker
|
||||
:type marker: Marker enum
|
||||
:return: filtered version of marker
|
||||
"""
|
||||
if isinstance(marker, Marker):
|
||||
marker_value = marker.value
|
||||
if marker_value == "random":
|
||||
marker_list = list(Marker)
|
||||
marker_list.remove(Marker.RANDOM)
|
||||
marker_value = random.choice(marker_list).value
|
||||
return marker_value
|
||||
return None
|
||||
|
||||
|
||||
def filter_float(value):
|
||||
"""
|
||||
Filter given float value.
|
||||
|
@ -292,6 +310,7 @@ def plot_params_filter(
|
|||
spot_size=None,
|
||||
size=None,
|
||||
projection=None,
|
||||
marker=None,
|
||||
alpha=None,
|
||||
linewidth=None):
|
||||
"""
|
||||
|
@ -311,6 +330,8 @@ def plot_params_filter(
|
|||
:type size: tuple
|
||||
:param projection: projection type
|
||||
:type projection: str
|
||||
:param marker: marker type
|
||||
:type marker: str
|
||||
:param alpha: point transparency
|
||||
:type alpha: float
|
||||
:param linewidth: width of line
|
||||
|
@ -329,6 +350,7 @@ def plot_params_filter(
|
|||
color, bgcolor = filter_color(color, bgcolor)
|
||||
cmap = filter_cmap(cmap)
|
||||
projection = filter_projection(projection)
|
||||
marker = filter_marker(marker)
|
||||
alpha = filter_float(alpha)
|
||||
linewidth = filter_float(linewidth)
|
||||
spot_size = filter_float(spot_size)
|
||||
|
@ -345,12 +367,14 @@ def plot_params_filter(
|
|||
size = g.size
|
||||
if projection is None:
|
||||
projection = g.projection
|
||||
if marker is None:
|
||||
marker = g.marker
|
||||
if alpha is None:
|
||||
alpha = g.alpha
|
||||
if linewidth is None:
|
||||
linewidth = g.linewidth
|
||||
g.color, g.bgcolor, g.cmap, g.spot_size, g.size, g.projection, g.alpha, g.linewidth = \
|
||||
color, bgcolor, cmap, spot_size, size, projection, alpha, linewidth
|
||||
g.color, g.bgcolor, g.cmap, g.spot_size, g.size, g.projection, g.marker, g.alpha, g.linewidth = \
|
||||
color, bgcolor, cmap, spot_size, size, projection, marker, alpha, linewidth
|
||||
|
||||
|
||||
def generate_params_filter(
|
||||
|
@ -452,6 +476,7 @@ def _GI_initializer(g, function1, function2):
|
|||
g.spot_size = DEFAULT_SPOT_SIZE
|
||||
g.size = DEFAULT_IMAGE_SIZE
|
||||
g.projection = DEFAULT_PROJECTION
|
||||
g.marker = DEFAULT_MARKER
|
||||
g.alpha = DEFAULT_ALPHA
|
||||
g.linewidth = DEFAULT_LINEWIDTH
|
||||
g.depth = DEFAULT_DEPTH
|
||||
|
@ -510,6 +535,7 @@ def save_data_file(g, file_adr):
|
|||
"cmap": _serialize_cmap(g.cmap),
|
||||
"spot_size": g.spot_size,
|
||||
"projection": g.projection,
|
||||
"marker": g.marker,
|
||||
"alpha": g.alpha,
|
||||
"linewidth": g.linewidth,
|
||||
"depth": g.depth
|
||||
|
@ -554,6 +580,7 @@ def save_config_file(g, file_adr):
|
|||
"cmap": _serialize_cmap(g.cmap),
|
||||
"spot_size": g.spot_size,
|
||||
"projection": g.projection,
|
||||
"marker": g.marker,
|
||||
"alpha": g.alpha,
|
||||
"linewidth": g.linewidth,
|
||||
"depth": g.depth
|
||||
|
@ -723,6 +750,7 @@ def load_data(g, data):
|
|||
g.cmap = _load_cmap(plot_config)
|
||||
g.spot_size = plot_config.get("spot_size", DEFAULT_SPOT_SIZE)
|
||||
g.projection = plot_config.get("projection", DEFAULT_PROJECTION)
|
||||
g.marker = plot_config.get("marker", DEFAULT_MARKER)
|
||||
g.alpha = plot_config.get("alpha", DEFAULT_ALPHA)
|
||||
g.linewidth = plot_config.get("linewidth", DEFAULT_LINEWIDTH)
|
||||
g.depth = plot_config.get("depth", DEFAULT_DEPTH)
|
||||
|
@ -761,6 +789,7 @@ def load_config(g, config):
|
|||
g.cmap = _load_cmap(plot_config)
|
||||
g.spot_size = plot_config.get("spot_size", DEFAULT_SPOT_SIZE)
|
||||
g.projection = plot_config.get("projection", DEFAULT_PROJECTION)
|
||||
g.marker = plot_config.get("marker", DEFAULT_MARKER)
|
||||
g.alpha = plot_config.get("alpha", DEFAULT_ALPHA)
|
||||
g.linewidth = plot_config.get("linewidth", DEFAULT_LINEWIDTH)
|
||||
g.depth = plot_config.get("depth", DEFAULT_DEPTH)
|
||||
|
|
|
@ -95,6 +95,7 @@ class GenerativeImage:
|
|||
spot_size=None,
|
||||
size=None,
|
||||
projection=None,
|
||||
marker=None,
|
||||
alpha=None,
|
||||
linewidth=None):
|
||||
"""
|
||||
|
@ -112,6 +113,8 @@ class GenerativeImage:
|
|||
:type size: tuple
|
||||
:param projection: projection type
|
||||
:type projection: str
|
||||
:param marker: marker type
|
||||
:type marker: str
|
||||
:param alpha: point transparency
|
||||
:type alpha: float
|
||||
:param linewidth: width of line
|
||||
|
@ -126,6 +129,7 @@ class GenerativeImage:
|
|||
spot_size,
|
||||
size,
|
||||
projection,
|
||||
marker,
|
||||
alpha,
|
||||
linewidth)
|
||||
fig = plt.figure()
|
||||
|
@ -139,7 +143,8 @@ class GenerativeImage:
|
|||
c=self.color,
|
||||
cmap=self.cmap,
|
||||
s=self.spot_size,
|
||||
lw=self.linewidth)
|
||||
lw=self.linewidth,
|
||||
marker=self.marker)
|
||||
ax.set_axis_off()
|
||||
ax.patch.set_zorder(-1)
|
||||
ax.add_artist(ax.patch)
|
||||
|
|
|
@ -27,6 +27,7 @@ DEFAULT_IMAGE_SIZE = (10, 10)
|
|||
DEFAULT_SPOT_SIZE = 0.01
|
||||
DEFAULT_DEPTH = 1
|
||||
DEFAULT_PROJECTION = "rectilinear"
|
||||
DEFAULT_MARKER = "."
|
||||
SEED_LOWER_BOUND = 0
|
||||
SEED_UPPER_BOUND = 2**20
|
||||
VALID_COLORS = list(dict(mcolors.BASE_COLORS, **mcolors.CSS4_COLORS).keys())
|
||||
|
@ -69,6 +70,42 @@ class Projection(Enum):
|
|||
RANDOM = "random"
|
||||
|
||||
|
||||
class Marker(Enum):
|
||||
"""
|
||||
Samila Marker type class.
|
||||
|
||||
>>> marker = samila.Marker.POINT
|
||||
"""
|
||||
|
||||
DEFAULT = DEFAULT_MARKER
|
||||
POINT = "."
|
||||
PIXEL = ","
|
||||
CIRCLE = "o"
|
||||
TRIANGLE_DOWN = "v"
|
||||
TRIANGLE_UP = "^"
|
||||
TRIANGLE_LEFT = "<"
|
||||
TRIANGLE_RIGHT = ">"
|
||||
TRI_DOWN = "1"
|
||||
TRI_UP = "2"
|
||||
TRI_LEFT = "3"
|
||||
TRI_RIGHT = "4"
|
||||
OCTAGON = "8"
|
||||
SQUARE = "s"
|
||||
PENTAGON = "p"
|
||||
PLUS = "+"
|
||||
PLUS_FILLED = "P"
|
||||
STAR = "*"
|
||||
HEXAGON_VERTICAL = "h"
|
||||
HEXAGON_HORIZONTAL = "H"
|
||||
X = "x"
|
||||
X_FILLED = "X"
|
||||
DIAMOND = "D"
|
||||
DIAMON_THIN = "d"
|
||||
VLINE = "|"
|
||||
HLINE = "_"
|
||||
RANDOM = "random"
|
||||
|
||||
|
||||
RANDOM_COEF_LIST = [
|
||||
"random.uniform(-1,1)",
|
||||
"random.gauss(0,1)",
|
||||
|
|
|
@ -75,6 +75,15 @@ False
|
|||
>>> projection2 = filter_projection(Projection.RANDOM)
|
||||
>>> projection1 == projection2
|
||||
False
|
||||
>>> filter_marker(3)
|
||||
>>> filter_marker(Marker.POINT)
|
||||
'.'
|
||||
>>> random.seed(2)
|
||||
>>> marker1 = filter_marker(Marker.RANDOM)
|
||||
>>> random.seed(3)
|
||||
>>> marker2 = filter_marker(Marker.RANDOM)
|
||||
>>> marker1 == marker2
|
||||
False
|
||||
>>> distance_calc("test","test1")
|
||||
1
|
||||
>>> distance_calc("te1st","test")
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
>>> from matplotlib.colors import Colormap, ListedColormap
|
||||
>>> def guard(*args, **kwargs):
|
||||
... raise Exception("No internet connection!")
|
||||
>>> from samila import GenerativeImage, Projection
|
||||
>>> from samila import GenerativeImage, Projection, Marker
|
||||
>>> from samila.functions import is_same_data
|
||||
>>> import pickle
|
||||
>>> def f1(x,y):
|
||||
|
@ -53,7 +53,6 @@ True
|
|||
True
|
||||
>>> isinstance(result["message"], str)
|
||||
True
|
||||
>>> from samila import GenerativeImage, Projection
|
||||
>>> g.plot(projection=Projection.POLAR, color='red', bgcolor='black')
|
||||
>>> g.color
|
||||
'red'
|
||||
|
@ -84,7 +83,7 @@ True
|
|||
'#555555'
|
||||
>>> g.bgcolor
|
||||
'#aaaaaa'
|
||||
>>> g.plot(projection=Projection.POLAR, color="complement", bgcolor="complement")
|
||||
>>> g.plot(projection=Projection.POLAR, color="complement", bgcolor="complement", marker=Marker.X, spot_size=100)
|
||||
>>> g.color
|
||||
'#555555'
|
||||
>>> g.bgcolor
|
||||
|
@ -99,17 +98,19 @@ True
|
|||
>>> g.linewidth
|
||||
2.2
|
||||
>>> random.seed(2)
|
||||
>>> g.plot(color="random", bgcolor="random", projection=Projection.RANDOM)
|
||||
>>> color1, bgcolor1, projection1 = g.color, g.bgcolor, g.projection
|
||||
>>> g.plot(color="random", bgcolor="random", projection=Projection.RANDOM, marker=Marker.RANDOM)
|
||||
>>> color1, bgcolor1, projection1, marker1 = g.color, g.bgcolor, g.projection, g.marker
|
||||
>>> random.seed(3)
|
||||
>>> g.plot(color="random", bgcolor="random", projection=Projection.RANDOM)
|
||||
>>> color2, bgcolor2, projection2 = g.color, g.bgcolor, g.projection
|
||||
>>> g.plot(color="random", bgcolor="random", projection=Projection.RANDOM, marker=Marker.RANDOM)
|
||||
>>> color2, bgcolor2, projection2, marker2 = g.color, g.bgcolor, g.projection, g.marker
|
||||
>>> color1 == color2
|
||||
False
|
||||
>>> bgcolor1 == bgcolor2
|
||||
False
|
||||
>>> projection1 == projection2
|
||||
False
|
||||
>>> marker1 == marker2
|
||||
False
|
||||
>>> result = g.nft_storage(api_key="")
|
||||
>>> result['status']
|
||||
False
|
||||
|
|
Ładowanie…
Reference in New Issue