Skip to content
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

Add context manager for managing font properties #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
37 changes: 19 additions & 18 deletions scatterd/scatterd.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,24 +266,25 @@ def _set_figure_properties(X, labels, fontcolor, fontsize, xlabel, ylabel, title
if grid is True: grid='#dddddd'
None if zorder is None else zorder + 1
font = {'family': 'DejaVu Sans', 'weight': fontweight, 'size': np.maximum(fontsize, 1)}
matplotlib.rc('font', **font)
for item in ([ax.title, ax.xaxis.label, ax.yaxis.label] + ax.get_xticklabels() + ax.get_yticklabels()):
item.set_fontsize(20)

# Plot labels
if (labels is not None) and (fontcolor is not None):
for uilabel in fontcolor.keys():
# Compute median for better center compared to mean
XYmean = np.mean(X[labels==uilabel, :], axis=0)
if X.shape[1]==2:
ax.text(XYmean[0], XYmean[1], str(uilabel), color=fontcolor.get(uilabel), fontdict={'weight': fontweight, 'size': fontsize}, zorder=zorder)
else:
ax.text(XYmean[0], XYmean[1], XYmean[2], str(uilabel), color=fontcolor.get(uilabel), fontdict={'weight': fontweight, 'size': fontsize})

# Labels on axis
if (xlabel is not None) and (xlabel!=''): ax.set_xlabel(xlabel)
if (ylabel is not None) and (ylabel!=''): ax.set_ylabel(ylabel)
if (title is not None) and (title!=''): ax.set_title(title)
with matplotlib.rc_context():
matplotlib.rc('font', **font)
for item in ([ax.title, ax.xaxis.label, ax.yaxis.label] + ax.get_xticklabels() + ax.get_yticklabels()):
item.set_fontsize(20)

# Plot labels
if (labels is not None) and (fontcolor is not None):
for uilabel in fontcolor.keys():
# Compute median for better center compared to mean
XYmean = np.mean(X[labels==uilabel, :], axis=0)
if X.shape[1]==2:
ax.text(XYmean[0], XYmean[1], str(uilabel), color=fontcolor.get(uilabel), fontdict={'weight': fontweight, 'size': fontsize}, zorder=zorder)
else:
ax.text(XYmean[0], XYmean[1], XYmean[2], str(uilabel), color=fontcolor.get(uilabel), fontdict={'weight': fontweight, 'size': fontsize})

# Labels on axis
if (xlabel is not None) and (xlabel!=''): ax.set_xlabel(xlabel)
if (ylabel is not None) and (ylabel!=''): ax.set_ylabel(ylabel)
if (title is not None) and (title!=''): ax.set_title(title)

# set background to none
ax.set_facecolor('none')
Expand Down