Skip to content

Commit

Permalink
Merge branch 'fix-branch'
Browse files Browse the repository at this point in the history
  • Loading branch information
paulobndes committed Sep 6, 2021
2 parents 8072e73 + 8dd98d6 commit dac3ecb
Show file tree
Hide file tree
Showing 4 changed files with 177 additions and 45 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
__pycache__
.ipynb_checkpoints
charp.py
77 changes: 77 additions & 0 deletions charp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
"""
CharP is Charts for Paulo — Paulos aux functions and preferences for beautiful
and functional charts
"""

import matplotlib as mpl
import matplotlib.pyplot as plt


plt.style.use("./paulo.mplstyle")

color_highlight = plt.rcParams["lines.color"] # default is orange
color_highlight2 = (0, 153, 51)
color_highlight3 = (30, 66, 139)


def set_title(title, fontsize=16, ax=None):
"Title always aligned to the left axis label"
# https://stackoverflow.com/questions/62997001/matplotlib-how-to-exact-align-the-title-to-the-y-label
if ax is None:
ax = plt.gca()
plt.gcf().canvas.draw() # without this, it won't work
x_min = min(lb.get_window_extent().x0 for lb in ax.get_yticklabels())
x_min = min(mpl.text.Text.get_window_extent(lb).x0 for lb in ax.get_yticklabels())
x, _ = ax.transAxes.inverted().transform([x_min, 0])
plt.gcf().canvas.draw() # without this, it won't work
return ax.set_title(title, ha="left", x=x, fontsize=fontsize)


def rotate_xlabels(angle=45):
plt.tick_params(axis="x", labelrotation=angle, ha="right")


def barh(ax=None):
if ax is None:
ax = plt.gca()
# label on top
ax.tick_params(
axis="x",
top=False,
labeltop=True,
bottom=False,
labelbottom=False,
pad=-13, # hardcoded looks wrong
)
# white grid
ax.grid(axis="x", color="white", linestyle="--")
ax.grid(False, axis="y")
ax.set_axisbelow(False)

# spines
ax.spines["bottom"].set_visible(False)
# identar à direita?


def bar(ax=None):
if ax is None:
ax = plt.gca()
# white grid
ax.grid(axis="y", color="white", linestyle="dotted")
ax.set_axisbelow(False)

ax.tick_params(
axis="x", bottom=False,
)


def example_chart():
# in ipython type: %matplotlib
import seaborn as sns

df = sns.load_dataset("iris")
fig = plt.figure()
ax = fig.gca()
plt.plot(df.query('species=="virginica"').petal_length)
ax.set_title("Maria vai com as outras")
return ax
2 changes: 1 addition & 1 deletion paulo.mplstyle
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
## ***************************************************************************
## See https://matplotlib.org/api/artist_api.html#module-matplotlib.lines
## for more information on line properties.
lines.linewidth: 1.5 # line width in points
lines.linewidth: 2.5 # line width in points
#lines.linestyle: - # solid line
lines.color: orange # has no affect on plot(); see axes.prop_cycle
#lines.marker: None # the default marker
Expand Down
Loading

0 comments on commit dac3ecb

Please sign in to comment.