Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 3 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,9 @@ The user can quickly create a PV array with ``pvfactors``, and manipulate it wit
df_inputs.albedo)

The user can then plot the PV array geometry at any given time of the simulation:

Please note that the plot is generated using matplotlib, which is
not included in the default dependencies, it can be installed
using `pip install solarfactors[plot]`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GitHub is displaying this in the same paragraph as line 119, making it flow a little poorly. Maybe edit the code block to something like:

    # Plot pvarray shapely geometries (needs matplotlib: pip install solarfactors[plot])


.. code:: python

Expand Down
17 changes: 17 additions & 0 deletions docs/sphinx/whatsnew/v1.6.2.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
.. _whatsnew_162:

v1.6.2 (??)
==========


Maintenance
-----------
* Matplotlib is now an optional dependency. (:issue:`31`)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please move it to v1.6.1, which hasn't been released yet



Documentation
-------------

Contributors
------------
* Kurt Rhee (:ghuser:`kurt-rhee`)
68 changes: 68 additions & 0 deletions pvfactors/geometry/_optional_imports.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
"""Utility module for handling optional dependencies for plotting functionality."""

import functools


def _matplotlib_import_error_message():
"""Generate helpful error message for missing matplotlib."""
return (
"matplotlib is required for plotting functionality. "
"Install it using one of the following methods:\n"
" pip install solarfactors[plot]\n"
" pip install matplotlib\n"
" conda install matplotlib"
)


def _check_matplotlib():
"""
Check if matplotlib is available and raise ImportError if not.
"""
try:
import matplotlib # noqa: F401

return True
except ImportError:
raise ImportError(_matplotlib_import_error_message())


def requires_matplotlib(func):
"""Decorator to check for matplotlib availability before executing
plotting functions.

Parameters
----------
func : callable
Function that requires matplotlib

Returns
-------
callable
Wrapped function that checks for matplotlib before execution
"""

@functools.wraps(func)
def wrapper(*args, **kwargs):
_check_matplotlib()
return func(*args, **kwargs)

return wrapper


def optional_matplotlib_import():
"""Import matplotlib.pyplot with optional handling.

Returns
-------
module or None
matplotlib.pyplot module if available, None otherwise

Raises
------
ImportError
If matplotlib is not available with helpful installation message
"""
_check_matplotlib()
import matplotlib.pyplot as plt # noqa: F401

return plt
Loading