|
アーティストが作成されるとすぐに、"CN" の色がRGBAに変換されます。 例えば、
import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl
th = np.linspace(0, 2*np.pi, 128)
def demo(sty):
mpl.style.use(sty)
fig, ax = plt.subplots(figsize=(3, 3))
ax.set_title('style: {!r}'.format(sty), color='C0')
ax.plot(th, np.cos(th), 'C1', label='C1')
ax.plot(th, np.sin(th), 'C2', label='C2')
ax.legend()
demo('default')
demo('seaborn')
plt.show()


最初の色をタイトルに使用し、各スタイルの mpl.rcParams['axes.prop_cycle'] の 2 番目と 3 番目の色を使用してプロットします。
Python 3.11.6 では、下記のような警告があるが、実行できる。
M:\______s\Specifying_Colors_01.py:9: MatplotlibDeprecationWarning:
The seaborn styles shipped by Matplotlib are deprecated since 3.6,
as they no longer correspond to the styles shipped by seaborn. However,
they will remain available as 'seaborn-v0_8-<style>'. Alternatively, directly use
the seaborn API instead.
mpl.style.use(sty)
Python 3.12.0 では、下記のようなエラーがあり、実行できない。
Traceback (most recent call last):
File "C:\Program Files\Python312\Lib\site-packages\matplotlib\style\core.py", line 137, in use
style = _rc_params_in_file(style)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Program Files\Python312\Lib\site-packages\matplotlib\__init__.py", line 879, in _rc_params_in_file
with _open_file_or_url(fname) as fd:
File "C:\Program Files\Python312\Lib\contextlib.py", line 137, in __enter__
return next(self.gen)
^^^^^^^^^^^^^^
File "C:\Program Files\Python312\Lib\site-packages\matplotlib\__init__.py", line 856, in _open_file_or_url
with open(fname, encoding='utf-8') as f:
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: 'seaborn'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "E:\______\Specifying_Colors_01.py", line 19, in
demo('seaborn')
File "E:\______\Specifying_Colors_01.py", line 9, in demo
mpl.style.use(sty)
File "C:\Program Files\Python312\Lib\site-packages\matplotlib\style\core.py", line 139, in use
raise OSError(
OSError: 'seaborn' is not a valid package style, path of style file, URL of style file, or library style name
(library styles are listed in `style.available`)
Top
|