Skip to content

Allow to set hatches in 'area' plots #12354

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

Open
wavexx opened this issue Feb 16, 2016 · 13 comments
Open

Allow to set hatches in 'area' plots #12354

wavexx opened this issue Feb 16, 2016 · 13 comments

Comments

@wavexx
Copy link

wavexx commented Feb 16, 2016

I'd like to be able to set the hatch styles (using a cycler) in plot(kind='area').
This would allow me to produce black&white plots correctly with more than two categories.

@jreback jreback added the Visualization plotting label Feb 17, 2016
@jreback
Copy link
Contributor

jreback commented Feb 17, 2016

@TomAugspurger ?

@TomAugspurger
Copy link
Contributor

@wavexx can you show an example of the matplotlib code needed to get the hatching on an area plot?

@wavexx
Copy link
Author

wavexx commented Feb 17, 2016

I didn't check how area plots are made internally. It varies a bit depending on which call you're using, but most filling functions in mpl support the hatch or hatches kwarg.

http://matplotlib.org/examples/pylab_examples/contourf_hatching.html

It's also supported by fill_between (hatch).

https://stackoverflow.com/questions/18386106/matplotlib-hatched-fill-between-without-edges

I tried to set a cycler('hatch') as my default axes.prop_cycle, but it tries to set the hatch style for the lines as well (and this obviously fails).

@jreback jreback added this to the 0.18.2 milestone Apr 17, 2016
@jreback jreback modified the milestones: Next Major Release, 0.18.2 Jun 30, 2016
@dschien
Copy link

dschien commented Jun 28, 2017

@wavexx I am right that it currently is not possible at all to set hatches to area plots - not just using a cycler?

I am thinking that is the case because I tried the following without success:

ax = pd.plot(kind='area')
hatches=['.', '/', '\\', None, '\\\\', '*']
for i, a in enumerate(ax.collections):
    hatch = hatches[i % len(hatches)]
    a.set_hatch(hatch)

Thanks for any info

@wavexx
Copy link
Author

wavexx commented Jun 28, 2017

As I wrote, you have to be careful to apply the style only to areas, but otherwise it will work:

pd.DataFrame([1,2,3]).plot(kind='area').collections[0].set_hatch('.')

Unfortunately this method is not scalable to anything but the simplest plot.
For black&white plots I still have to use MPL directly

@dschien
Copy link

dschien commented Jun 29, 2017

Ok. Thanks for the confirmation. Will try

@dschien
Copy link

dschien commented Jun 30, 2017

@wavexx Sorry to be a pain but your one liner does not get hatches in jupyter notebook on OSX python 3.6.1 with the below packages.

Any ideas?

alabaster==0.7.10
appdirs==1.4.3
appnope==0.1.0
appscript==1.0.1
asn1crypto==0.22.0
attrs==17.2.0
Automat==0.6.0
awscli==1.11.87
Babel==2.4.0
bleach==2.0.0
botocore==1.5.57
certifi==2017.4.17
cffi==1.10.0
chardet==3.0.3
click==6.7
colorama==0.3.9
constantly==15.1.0
cryptography==1.9
cssselect==1.0.1
cycler==0.10.0
decorator==4.0.11
docutils==0.13.1
entrypoints==0.2.2
et-xmlfile==1.0.1
-e git+https://github.com/dschien/PyExcelModelingHelper.git@9c2a47db71b4a9b6fb1cad6a4d624f44a2f58c1f#egg=excel_modelling_helper
Flask==0.12.2
Flask-SocketIO==2.8.6
google-api-python-client==1.6.2
html5lib==0.999999999
httplib2==0.10.3
idna==2.5
imagesize==0.7.1
incremental==17.5.0
ipykernel==4.6.1
ipynb==0.4
ipython==6.0.0
ipython-genutils==0.2.0
ipywidgets==6.0.0
itsdangerous==0.24
jdcal==1.3
jedi==0.10.2
Jinja2==2.9.6
jmespath==0.9.3
jsonschema==2.6.0
jupyter==1.0.0
jupyter-client==5.0.1
jupyter-cms==0.7.0
jupyter-console==5.1.0
jupyter-core==4.3.0
lxml==3.7.3
MarkupSafe==1.0
matplotlib==2.0.2
mistune==0.7.4
mpmath==0.19
nbconvert==5.2.1
nbformat==4.3.0
networkx==1.11
nose==1.3.7
notebook==5.0.0
numpy==1.12.1
oauth2client==4.1.0
olefile==0.44
onedrivesdk==1.1.8
openpyxl==2.4.8
packaging==16.8
pandas==0.20.1
pandoc==1.0.0b2
pandocfilters==1.4.1
parsel==1.2.0
patsy==0.4.1
pbr==3.0.1
pexpect==4.2.1
pickleshare==0.7.4
Pillow==4.1.1
ply==3.10
prompt-toolkit==1.0.14
psutil==5.2.2
ptyprocess==0.5.1
py4j==0.10.4
pyasn1==0.2.3
pyasn1-modules==0.0.8
pycparser==2.17
PyDispatcher==2.0.5
pydot-ng==1.0.0
pydotplus==2.0.2
Pygments==2.2.0
pygraphviz==1.3.1
pyOpenSSL==17.0.0
pypandoc==1.4
pyparsing==2.2.0
PyQt5==5.8.2
pyspark==2.1.0+hadoop2.7
python-dateutil==2.6.0
python-engineio==1.5.4
python-socketio==1.7.5
pytz==2017.2
PyYAML==3.12
pyzmq==16.0.2
qtconsole==4.3.0
queuelib==1.4.2
requests==2.17.3
rsa==3.4.2
s3transfer==0.1.10
scipy==0.19.0
Scrapy==1.4.0
service-identity==17.0.0
simplegeneric==0.8.1
simplejson==3.10.0
sip==4.19.2
six==1.10.0
snowballstemmer==1.2.1
Sphinx==1.6.2
sphinxcontrib-websupport==1.0.1
statsmodels==0.8.0
stevedore==1.22.0
sympy==1.0
tabulate==0.7.7
terminado==0.6
testpath==0.3.1
tornado==4.5.1
traitlets==4.3.2
Twisted==17.1.0
tzlocal==1.4
uritemplate==3.0.0
urllib3==1.21.1
virtualenv==15.1.0
virtualenv-clone==0.2.6
virtualenvwrapper==4.7.2
w3lib==1.17.0
wcwidth==0.1.7
webencodings==0.5.1
Werkzeug==0.12.2
Whoosh==2.7.4
widgetsnbextension==2.0.0
xarray==0.9.5
xlrd==1.0.0
xlwings==0.10.4
xlwt==1.2.0
zope.interface==4.4.1

@wavexx
Copy link
Author

wavexx commented Jun 30, 2017 via email

@dschien
Copy link

dschien commented Jun 30, 2017

Indeed on 3.5.1 with MPL 2.0.0 I do get hatches. It turns out the problem is MPL.
I also get hatches on python 3.6.1 with MPL 2.0.0. However, on 3.6.1 with MPL 2.0.2 no hatches. No error. Just no hatches.

@wavexx
Copy link
Author

wavexx commented Jun 30, 2017 via email

@dschien
Copy link

dschien commented Jun 30, 2017

Alright.

So setting hatches directly on the area plot fails.
If I do:
pd.DataFrame([1,2,3]).plot(kind='area', hatches=['.', '/', '\\'])
I get: AttributeError: Unknown property hatches

@wavexx
Copy link
Author

wavexx commented Jun 30, 2017 via email

@vwither
Copy link

vwither commented May 22, 2019

Hi, I have the same problem and it seems like it would make sense for pd.DataFrame.plot() to take the option keyed argument hatch = [] like it does for colors, marker, etc. It has been two years since this was first reported and I have seen several hacks o how to get around this on GitHub but is anyone working on this.

@mroeschke mroeschke removed this from the Contributions Welcome milestone Oct 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants