Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Use get_sample_data(..., asfileobj=False) less. #25472

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 15, 2023
Merged
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
14 changes: 4 additions & 10 deletions galleries/examples/showcase/stock_prices.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,10 @@
from matplotlib.cbook import get_sample_data
import matplotlib.transforms as mtransforms


def convertdate(x):
return np.datetime64(x, 'D')


fname = get_sample_data('Stocks.csv', asfileobj=False)
stock_data = np.genfromtxt(fname, encoding='utf-8', delimiter=',',
names=True, dtype=None, converters={0: convertdate},
skip_header=1)

with get_sample_data('Stocks.csv') as file:
stock_data = np.genfromtxt(
file, delimiter=',', names=True, dtype=None,
converters={0: lambda x: np.datetime64(x, 'D')}, skip_header=1)

fig, ax = plt.subplots(1, 1, figsize=(6, 8), layout='constrained')

Expand Down
14 changes: 7 additions & 7 deletions galleries/examples/subplots_axes_and_figures/figure_title.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
We can also add figure-level x- and y-labels using `.FigureBase.supxlabel` and
`.FigureBase.supylabel`.
"""

import matplotlib.pyplot as plt
import numpy as np

Expand All @@ -34,13 +35,10 @@
# `.FigureBase.supylabel` methods.


def convertdate(x):
return np.datetime64(x, 'D')

fname = get_sample_data('Stocks.csv', asfileobj=False)
stocks = np.genfromtxt(fname, encoding='utf-8', delimiter=',',
names=True, dtype=None, converters={0: convertdate},
skip_header=1)
with get_sample_data('Stocks.csv') as file:
stocks = np.genfromtxt(
file, delimiter=',', names=True, dtype=None,
converters={0: lambda x: np.datetime64(x, 'D')}, skip_header=1)

fig, axs = plt.subplots(4, 2, figsize=(9, 5), layout='constrained',
sharex=True, sharey=True)
Expand All @@ -51,3 +49,5 @@ def convertdate(x):
ax.set_title(column_name, fontsize='small', loc='left')
fig.supxlabel('Year')
fig.supylabel('Stock price relative to max')

plt.show()