Comments (6)
Checkout the documentation of the scaling library mizani, the functions are defined in there.
from plotnine.
Thank you for your help. In the example below I would like to extend the x labels up to 'Aug-2017' and have minor breaks shown up to that point as well.
How to achieve this? Do I need to use xlim()
? Is there a way to force mizani.breaks.date_breaks
to extend beyond the min & max datetime objects available from limits
object?
import random
import pandas as pd
from plotnine import ggplot, aes, geom_line
from plotnine.scales import scale_x_date, scale_y_continuous
from mizani.breaks import date_breaks, minor_breaks
from mizani.formatters import date_format
n = 30
df_test = pd.DataFrame({'date': pd.date_range(start='2017-01-01', periods=n, freq='1W', tz='UTC'),
'value': [random.randrange(0, 100) for x in range(n)]})
limits = df_test['date'].min(), df_test['date'].max()
breaks = date_breaks('1 month')
breaks_date = [x for x in breaks(limits)]
labels_date = date_format('%b-%Y')([x for x in breaks_date])
minor_breaks_x = minor_breaks(n=5)(breaks_date, limits)
ggplot(df_test, aes('date', 'value')) + \
geom_line() + \
scale_x_date(breaks=breaks_date, labels=labels_date, minor_breaks=minor_breaks_x) + \
scale_y_continuous()
from plotnine.
You do not need to create the explicit breaks and labels.
This should work
limits = df_test['date'].min(), df_test['date'].max() # change as you need
ggplot(df_test, aes('date', 'value')) + \
geom_line() + \
scale_x_date(breaks=date_breaks('1 month'),
labels=date_format('%b-%Y'),
minor_breaks=minor_breaks(n=5),
limits=limits) +\
scale_y_continuous()
You cannot use xlim()
or lims()
.
from plotnine.
Also, if all the intervals between the breaks are not equal, the minor breaks will not be able to extend beyond the limits. months
have varying number of days, so that creates unequal intervals.
from plotnine.
Noted, thank you for the quick feedback.
from plotnine.
Hi,
Very nice work with this package! I have been using extensively with great results.
Minor comment: it will be nice to add second resolution to the date_breaks() function in the mizani.breaks module.
I was able to add this line:
from matplotlib.dates import SecondLocator
in mizani.breaks breaks.py
and add the "SecondLocator" to same module:
LOCATORS = {
'second': SecondLocator,
'minute': MinuteLocator,
'hour': HourLocator,
'day': DayLocator,
'week': WeekdayLocator,
'month': MonthLocator,
'year': lambda interval: YearLocator(base=interval)
}
Code is working find, but don't know if there is any other dependencies!
Thanks you.
from plotnine.
Related Issues (20)
- Does plotnine 0.12.3 work with mizani 0.10.0? HOT 3
- Additions to facets HOT 2
- ggtitle or labs(title=) align left instead of center after updating from 0.10.1 to 0.12.3 HOT 2
- geom_text: can't use nudge_y and position=dodge HOT 2
- plotnine figure of ipynb with vscode is displayed too much larger than jupyter HOT 1
- AttributeError: 'RangeDiscrete' object has no attribute 'range' when calling scale_y_discrete HOT 3
- Add specific gene labels to geom_point volcanoplot HOT 2
- Tutorial ValueError: Unrecognised timezone class HOT 1
- Conditional colors for element_text() HOT 1
- `stat_ecdf` add `pad` argument
- geom_text cannot change vertical or horizontal alignment HOT 4
- Colored segments with manual group assignment breaks geom_path line endings
- No upper outline in `geom_ribbon()`
- Error when pickling an object obtained by draw() HOT 3
- Using a ggplot figure as standard Matplotlib device HOT 1
- Can the plotnine module draw significance markers? HOT 2
- In-place string scalars in `aes` HOT 1
- facet_grid throws an error: ValueError: No objects to concatenate HOT 2
- Breaks and labels in scale_color_identity don't match.
- FIPS Compliant
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from plotnine.