Skip to content

Commit

Permalink
Fixed precision error; upgrade ipython; added second axis example
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris committed Feb 16, 2019
1 parent a82aac4 commit b010c2d
Show file tree
Hide file tree
Showing 4 changed files with 139 additions and 2 deletions.
6 changes: 5 additions & 1 deletion chartify/_core/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ def __init__(self, chart, y_range_name="default"):
@staticmethod
def _axis_format_precision(max_value, min_value):
difference = abs(max_value - min_value)
precision = abs(int(np.floor(np.log10(difference)))) + 1
if difference:
precision = abs(int(np.floor(np.log10(difference)))) + 1
else:
precision = 1
print(precision)
zeros = ''.join(['0']*precision)
return "0,0.[{}]".format(zeros)

Expand Down
52 changes: 52 additions & 0 deletions chartify/examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -960,6 +960,58 @@ def _heatmap_example_1(average_price_by_fruit_and_country):
plot_heatmap.__doc__ = _core.plot.PlotCategoricalXY.heatmap.__doc__


@_print_source
def chart_second_axis():
"""
Docstring
"""
import chartify

# Generate example data
data = chartify.examples.example_data()

# Sum price grouped by date
price_by_date = (
data.groupby('date')['total_price'].sum()
.reset_index() # Move 'date' from index to column
)
price_by_date['triple_total_price'] = price_by_date['total_price'] * 3
price_by_date = price_by_date.sort_values('date')
print(price_by_date.head())
"""Print break"""
_second_axis_example(price_by_date)


@_print_source
def _second_axis_example(price_by_date):
"""Docstring"""
# Initialize chart with second_y_axis=True
ch = chartify.Chart(blank_labels=True,
x_axis_type='datetime',
y_axis_type='linear',
second_y_axis=True)
ch.set_title("Second Y axis")
# Plot the first axis
ch.plot.line(
data_frame=price_by_date,
x_column='date',
y_column='total_price')
ch.axes.set_yaxis_range(0, 50)
ch.axes.set_yaxis_label('First axis label')
ch.axes.set_yaxis_tick_format('0a')

# Plot the second axis
ch.second_axis.axes.set_yaxis_range(0, 80)
ch.second_axis.axes.set_yaxis_label('Second axis label')
ch.second_axis.plot.line(
# Data must be sorted by x column
data_frame=price_by_date,
x_column='date',
y_column='triple_total_price')
ch.second_axis.axes.set_yaxis_tick_format('0.0')
ch.show(_OUTPUT_FORMAT)


@_print_source
def style_color_palette_accent():
"""
Expand Down
81 changes: 81 additions & 0 deletions examples/Examples.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion requirements_dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ commonmark==0.5.4
recommonmark==0.4.0

prompt-toolkit==1.0.15
ipython==6.5.0
ipython==7.2.0
pytest==3.2.3
pytest-cov==2.5.1
coverage-badge==0.2.0
Expand Down

0 comments on commit b010c2d

Please sign in to comment.