-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
4 changed files
with
2,727 additions
and
5 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import pandas as pd | ||
from matplotlib.pyplot import Axes | ||
|
||
from forestplot import mforestplot | ||
|
||
dataname = "sleep-mmodel" | ||
data = f"https://raw.githubusercontent.com/lsys/forestplot/mplot/examples/data/{dataname}.csv" | ||
df = pd.read_csv(data) | ||
|
||
|
||
std_opts = dict( | ||
dataframe=df, | ||
estimate="coef", | ||
ll="ll", | ||
hl="hl", | ||
varlabel="var", | ||
model_col="model", | ||
) | ||
|
||
|
||
def test_vanilla_mplot(): | ||
ax = mforestplot(**std_opts) | ||
assert isinstance(ax, Axes) | ||
|
||
df_processed, ax = mforestplot(**std_opts, return_df=True) | ||
assert isinstance(ax, Axes) | ||
assert isinstance(df_processed, pd.DataFrame) | ||
|
||
|
||
def test_more_options(): | ||
df_processed, ax = mforestplot( | ||
**std_opts, | ||
color_alt_rows=True, | ||
groupvar="group", | ||
table=True, | ||
rightannote=["var", "group"], | ||
right_annoteheaders=["Variable", "Variable group"], | ||
xlabel="Coefficient (95% CI)", | ||
modellabels=["Have young kids", "Full sample"], | ||
xticks=[-1200, -600, 0, 600], | ||
return_df=True, | ||
# Additional kwargs for customizations | ||
**{ | ||
"marker": "D", # set maker symbol as diamond | ||
"markersize": 35, # adjust marker size | ||
"xlinestyle": (0, (10, 5)), # long dash for x-reference line | ||
"xlinecolor": "#808080", # gray color for x-reference line | ||
"xtick_size": 12, # adjust x-ticker fontsize | ||
"despine": False, | ||
}, | ||
) | ||
assert isinstance(ax, Axes) | ||
assert isinstance(df_processed, pd.DataFrame) |