Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
0a8ed00
Update the docs of the plotting and test_plotting modules
Azendae-Popo Oct 16, 2024
c3827d7
update docs workflows
Azendae-Popo Oct 16, 2024
07eb3cd
Fix Sphinx render
Azendae-Popo Oct 16, 2024
348334e
add docs
Azendae-Popo Oct 17, 2024
c0723ef
rename plotting --> chartly
Azendae-Popo Oct 17, 2024
9983d67
linting
Azendae-Popo Oct 17, 2024
84fcd79
Remove unused CSS and HTML files
Azendae-Popo Oct 17, 2024
e74ac60
WIP
Azendae-Popo Oct 17, 2024
e4b2254
update linting
Azendae-Popo Oct 17, 2024
4d31220
update workflows
Azendae-Popo Oct 17, 2024
90de96c
Update exclude_patterns in conf.py
Azendae-Popo Oct 17, 2024
169acc0
adds manifest.in file
Azendae-Popo Oct 17, 2024
4e7eb60
Adds CustomizePlot Class
Azendae-Popo Oct 21, 2024
a0a6a6a
update docs to reflect new changes
Azendae-Popo Oct 21, 2024
33126a0
Adds HatchArea Class
Azendae-Popo Oct 21, 2024
06263a6
update contour plot function
Azendae-Popo Oct 21, 2024
7c0298d
adds contour mask hatching
Azendae-Popo Oct 21, 2024
a8ecb64
WIP
Azendae-Popo Oct 21, 2024
1cf7114
update tests
Azendae-Popo Oct 22, 2024
191697a
add basemap to chartly
Azendae-Popo Oct 22, 2024
f244a2a
Merge branch 'staging' into ap/9/add-basemap/chartly
Azendae-Popo Oct 24, 2024
3a42658
Delete docs/Makefile
Azendae-Popo Oct 24, 2024
4da34b6
Delete docs/make.bat
Azendae-Popo Oct 24, 2024
ad0a5c1
Merge branch 'staging' into ap/9/add-basemap/chartly
Azendae-Popo Oct 28, 2024
dd33e8b
adds basemap feature to the class
Azendae-Popo Oct 28, 2024
2e814ba
update requirements
Azendae-Popo Oct 28, 2024
43ee21a
update requirement file
Azendae-Popo Oct 28, 2024
b33b0a7
linting
Azendae-Popo Oct 28, 2024
55f409e
Add Contour Plot and Hatching to basemap
Azendae-Popo Oct 28, 2024
542aa3f
Adds annotations class to basemap
Azendae-Popo Oct 29, 2024
5007448
WIP
Azendae-Popo Oct 29, 2024
a1de828
Merge branch 'staging' into ap/9/add-basemap/chartly
Azendae-Popo Nov 21, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions chartly/chartly.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from .base import Plot
from .charts import (
CDF,
Basemap,
BoxPlot,
Contour,
Density,
Expand Down Expand Up @@ -86,6 +87,7 @@ def __init__(self, args={}):
"line_plot": LinePlot,
"contour": Contour,
"normal_cdf": NormalCDF,
"basemap": Basemap,
"scatter": ScatterPlot,
"dotplot": DotPlot,
}
Expand Down
172 changes: 172 additions & 0 deletions chartly/charts.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from matplotlib.colors import LinearSegmentedColormap
from matplotlib.patches import Rectangle
from matplotlib.ticker import MaxNLocator
from mpl_toolkits.basemap import Basemap as bmap
from scipy.stats import norm

from .base import CustomizePlot, Plot
Expand Down Expand Up @@ -748,3 +749,174 @@ def __call__(self):
# label the axes
self.axes_labels["show_legend"] = False
self.label_axes()


class Basemap(Plot, CustomizePlot):
"""Class to plot a basemap.

:param dict args: the master dictionary containing the required fields.

Required Keys
- data: the data to plot

Optional Keys
- customs: the plot's customization
- axes_labels: the axes labels

Available Customizations:
- proj: the projection of the map, default is "ortho"
- draw_coastlines: whether to draw coastlines, default is True
- fillcontinents: whether to fill continents, default is False
- draw_countries: whether to draw countries, default is False
- draw_states: whether to draw states, default is False
- draw_rivers: whether to draw rivers, default is False
- bluemarble: whether to use the bluemarble map, default is False
- shaderelief: whether to use the shaded relief map, default is False
- draw_parallels: whether to draw parallels, default is False
- draw_meridians: whether to draw meridians, default is False
"""

def __init__(self, args):
"""Initialize the Basemap Class."""
# Get the basemap arguments
self.args = args

# Extract the customs
customs_ = self.args.get("customs", {})

# Initialize the Plot Class
super().__init__(self.args)

# Initialize the CustomizePlot Class
CustomizePlot.__init__(self, customs_)

def defaults(self):
return {
"proj": "ortho",
"draw_coastlines": True,
"fillcontinents": False,
"draw_countries": False,
"draw_states": False,
"draw_rivers": False,
"bluemarble": False,
"shaderelief": False,
"draw_parallels": False,
"draw_meridians": False,
"contour": False,
"contourf": False,
"hatch": False,
"hatch_customs": {},
"mask": None,
"contour_customs": {},
"annotate": False,
"annotate_customs": {},
}

def __call__(self):
"""Plot a basemap."""
map_ = bmap(projection=self.customs["proj"], lat_0=0, lon_0=0)

basemap_methods = {
"draw_coastlines": map_.drawcoastlines,
"fillcontinents": map_.fillcontinents,
"draw_countries": map_.drawcountries,
"draw_states": map_.drawstates,
"draw_rivers": map_.drawrivers,
"bluemarble": map_.bluemarble,
"shaderelief": map_.shadedrelief,
"draw_parallels": lambda: map_.drawparallels(np.arange(-90, 90, 30)),
"draw_meridians": lambda: map_.drawmeridians(np.arange(0, 360, 60)),
}

for key, method in basemap_methods.items():
if self.customs.get(key):
method()

# vAdd Contour or filled contour
for contour_type in ["contour", "contourf"]:
if self.customs.get(contour_type):
cs = getattr(map_, contour_type)(
self.data[0],
self.data[1],
self.data[2],
)

# Add Contour Hatch
if self.customs.get("hatch"):
self.customs["hatch_customs"].update({"ax": map_})
if self.customs["hatch_customs"]["type"] == "mask":
self.customs["hatch_customs"]["data"] = [
self.data[0],
self.data[1],
self.customs["mask"],
]
hatch = HatchArea(self.customs["hatch_customs"])
hatch()

# Add Annotations
if self.customs.get("annotate"):
self.customs["annotate_customs"].update({"ax": self.ax, "map": map_})
annotate = AnnotateBasemap(self.customs["annotate_customs"])
annotate()

self.axes_labels["show_legend"] = False
self.label_axes()


class AnnotateBasemap(CustomizePlot):
"""Class to annotate a basemap."""

def __init__(self, args):
"""Initialize the AnnotateBasemap Class."""
# Get the basemap arguments
self.args = args

# Extract the customs
customs_ = self.args.get("customs", {})

# Initialize the CustomizePlot Class
super().__init__(self.args)

def defaults(self):
return {
"ax": None,
"map": None,
"text": None,
"xy": None,
"xytext": None,
"arrowprops": None,
"fontsize": 12,
"color": "black",
}

def __call__(self):
"""Annotate a basemap."""
assert self.customs["xy"] is not None, "xy positions must be provided"

map_ = self.customs["map"]
ax = self.customs["ax"]

if self.customs["xytext"] is not None:
assert len(self.customs["xy"]) == len(
self.customs["xytext"]
), "xy positions and xytext positions must be of the same length"

for idx in range(len(self.customs["xy"])):
ax.annotate(
self.customs["text"][idx],
xy=map_(*self.customs["xy"][idx]),
xytext=map_(*self.customs["xytext"][idx]),
arrowprops=self.customs["arrowprops"],
fontsize=self.customs["fontsize"],
color=self.customs["color"],
)

else:
for idx in range(len(self.customs["xy"])):
ax.annotate(
self.customs["text"][idx],
xy=map_(*self.customs["xy"][idx]),
arrowprops=self.customs["arrowprops"],
fontsize=self.customs["fontsize"],
color=self.customs["color"],
)
2 changes: 1 addition & 1 deletion docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -187,4 +187,4 @@ Indices and tables

* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`
* :ref:`search`
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
basemap
cloud-sptheme==1.10.1.post20200504175005
matplotlib==3.9.1
matplotlib==3.8.4
numpy==1.26.4
pytest==8.3.2
pytest-cov==5.0.0
Expand Down
3 changes: 2 additions & 1 deletion requirements/production.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
basemap==1.4.1
cloud-sptheme==1.10.1.post20200504175005
matplotlib==3.9.1
matplotlib==3.8.4
numpy==1.26.4
pytest==8.3.2
pytest-cov==5.0.0
Expand Down
3 changes: 2 additions & 1 deletion requirements/staging.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
basemap==1.4.1
cloud-sptheme==1.10.1.post20200504175005
matplotlib==3.9.1
matplotlib==3.8.4
numpy==1.26.4
pytest==8.3.2
pytest-cov==5.0.0
Expand Down
3 changes: 2 additions & 1 deletion requirements/testing.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
basemap==1.4.1
cloud-sptheme==1.10.1.post20200504175005
matplotlib==3.9.1
matplotlib==3.8.4
numpy==1.26.4
pytest==8.3.2
pytest-cov==5.0.0
Expand Down