Skip to content

Commit f52ed2a

Browse files
authored
Merge branch 'master' into minorgrid
2 parents c1dac39 + 2a1ff18 commit f52ed2a

File tree

12 files changed

+146
-73
lines changed

12 files changed

+146
-73
lines changed

.circleci/config.yml

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
version: 2
2+
3+
jobs:
4+
5+
# # python2:
6+
# build:
7+
# working_directory: ~/matplotlib2tikz
8+
# docker:
9+
# - image: ubuntu:17.10
10+
# steps:
11+
# - run: apt-get update
12+
# # don't install sympy with apt: it pulls in texlive which takes for ever
13+
# # to download and install
14+
# - run: apt-get install -y git python-pip pandoc
15+
# - run: pip2 install -U pytest pytest-cov pylint
16+
# - checkout
17+
# - run: pip2 install -r test_requirements.txt
18+
# - run: pip2 install .
19+
# # lint
20+
# - run: pylint matplotlib2tikz/
21+
# - run: pylint test/*.py
22+
# # make sure that rst converts correctly
23+
# - run: cat README.md | sed 's_<img src="\([^"]*\)" width="\([^"]*\)">_![](\1){width="\2"}_g' > /tmp/README.md
24+
# - run: pandoc /tmp/README.md -o README.rst
25+
# - run: pip2 install docutils pygments
26+
# - run: python setup.py check -r -s
27+
# # The tests
28+
# - run: cd test/ && MPLBACKEND=Agg pytest --cov matplotlib2tikz
29+
30+
# python3:
31+
build:
32+
working_directory: ~/matplotlib2tikz
33+
docker:
34+
- image: ubuntu:17.10
35+
environment:
36+
- TEXMFLOCAL: "/tmp/texmf/"
37+
steps:
38+
- run: apt-get update
39+
- run: apt-get install -y texlive-latex-base texlive-latex-extra python3-pip python3-tk wget poppler-utils
40+
- run: pip3 install -U pytest pytest-cov code_extract pylint
41+
- checkout
42+
- run: cd ~/matplotlib2tikz
43+
- run: code-extract README.md test/zzz_readme_test.py --filter python,test
44+
# install latest pgfplots
45+
- run: mkdir -p $TEXMFLOCAL
46+
- run: wget http://mirrors.ctan.org/install/graphics/pgf/contrib/pgfplots.tds.zip -O /tmp/pgfplots.zip
47+
- run: unzip /tmp/pgfplots.zip -d $TEXMFLOCAL
48+
- run: texhash
49+
# install
50+
- run: pip3 install -r test_requirements.txt
51+
- run: pip3 install .
52+
# lint
53+
- run: pylint setup.py
54+
- run: pylint matplotlib2tikz/
55+
- run: pylint test/*.py
56+
# The actual test
57+
- run: cd test/ && MPLBACKEND=Agg pytest --cov matplotlib2tikz
58+
# submit to codecov
59+
- run: apt-get install -y curl
60+
- run: bash <(curl -s https://codecov.io/bash)
61+
62+
# workflow builds don't support forked PRs yet, cf.
63+
# <https://circleci.com/docs/2.0/faq/#can-i-build-fork-prs-using-workflows>.
64+
# workflows:
65+
# version: 2
66+
# build-and-test:
67+
# jobs:
68+
# - python2
69+
# - python3

.travis.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ dist: trusty
33
language: python
44

55
python:
6-
- '2.7'
6+
# The images have different hashes on Python 2.7.
7+
# - '2.7'
78
- '3.6'
89

910
addons:
@@ -31,14 +32,14 @@ addons:
3132
- python-tk
3233

3334
before_install:
34-
- pip install pytest pytest-cov code_extract pylint
35+
- pip3 install pytest pytest-cov code_extract pylint
3536
# Make sure to put the readme test at the very end; otherwise it's messing
3637
# around with the other tests.
3738
- code_extract README.md test/zzz_readme_test.py --filter python,test
3839

3940
install:
40-
- pip install -r test_requirements.txt
41-
- pip install .
41+
- pip3 install -r test_requirements.txt
42+
- pip3 install .
4243

4344
cache: pip
4445

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# matplotlib2tikz
22

3-
[![Build Status](https://travis-ci.org/nschloe/matplotlib2tikz.svg?branch=master)](https://travis-ci.org/nschloe/matplotlib2tikz)
3+
[![CircleCI](https://circleci.com/gh/nschloe/matplotlib2tikz.svg?style=svg)](https://circleci.com/gh/nschloe/matplotlib2tikz)
44
[![codecov](https://codecov.io/gh/nschloe/matplotlib2tikz/branch/master/graph/badge.svg)](https://codecov.io/gh/nschloe/matplotlib2tikz)
55
[![Documentation Status](https://readthedocs.org/projects/matplotlib2tikz/badge/?version=latest)](https://readthedocs.org/projects/matplotlib2tikz/?badge=latest)
66
[![PyPi Version](https://img.shields.io/pypi/v/matplotlib2tikz.svg)](https://pypi.python.org/pypi/matplotlib2tikz)

matplotlib2tikz/color.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# -*- coding: utf-8 -*-
22
#
3+
from __future__ import division
4+
35
import matplotlib as mpl
46
import numpy
57

@@ -18,6 +20,15 @@ def mpl_color2xcolor(data, matplotlib_color):
1820
xcol = None
1921
# RGB values (as taken from xcolor.dtx):
2022
available_colors = {
23+
# List white first such that for gray values, the combination
24+
# white!<x>!black is preferred over, e.g., gray!<y>!black. Note that
25+
# the order of the dictionary is respected from Python 3.6 on.
26+
'white': numpy.array([1, 1, 1]),
27+
'lightgray': numpy.array([0.75, 0.75, 0.75]),
28+
'gray': numpy.array([0.5, 0.5, 0.5]),
29+
'darkgray': numpy.array([0.25, 0.25, 0.25]),
30+
'black': numpy.array([0, 0, 0]),
31+
#
2132
'red': numpy.array([1, 0, 0]),
2233
'green': numpy.array([0, 1, 0]),
2334
'blue': numpy.array([0, 0, 1]),
@@ -28,11 +39,6 @@ def mpl_color2xcolor(data, matplotlib_color):
2839
'purple': numpy.array([0.75, 0, 0.25]),
2940
'teal': numpy.array([0, 0.5, 0.5]),
3041
'violet': numpy.array([0.5, 0, 0.5]),
31-
'black': numpy.array([0, 0, 0]),
32-
'darkgray': numpy.array([0.25, 0.25, 0.25]),
33-
'gray': numpy.array([0.5, 0.5, 0.5]),
34-
'lightgray': numpy.array([0.75, 0.75, 0.75]),
35-
'white': numpy.array([1, 1, 1])
3642
# The colors cyan, magenta, yellow, and olive are also
3743
# predefined by xcolor, but their RGB approximation of the
3844
# native CMYK values is not very good. Don't use them here.
@@ -71,4 +77,5 @@ def mpl_color2xcolor(data, matplotlib_color):
7177
# Lookup failed, add it to the custom list.
7278
xcol = 'color' + str(len(data['custom colors']))
7379
data['custom colors'][xcol] = my_col[:3]
80+
7481
return data, xcol, my_col

matplotlib2tikz/image.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,15 @@ def draw_image(data, obj):
4343
# RGB (+alpha) information at each point
4444
assert len(dims) == 3 and dims[2] in [3, 4]
4545
# convert to PIL image
46-
if obj.origin == "lower":
46+
if obj.origin == 'lower':
4747
img_array = numpy.flipud(img_array)
48-
image = PIL.Image.fromarray(img_array)
48+
49+
# Convert mpl image to PIL
50+
image = PIL.Image.fromarray(numpy.uint8(img_array*255))
51+
52+
# If the input image is PIL:
53+
# image = PIL.Image.fromarray(img_array)
54+
4955
image.save(filename, origin=obj.origin)
5056

5157
# write the corresponding information to the TikZ file

matplotlib2tikz/text.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,21 @@ def draw_text(data, obj):
150150
# 'heavy' : 800,
151151
# 'extra bold' : 800,
152152
# 'black' : 900}
153-
if obj.get_weight() > 550:
153+
#
154+
# get_weights returns a numeric value in the range 0-1000 or one of
155+
# ‘light’, ‘normal’, ‘regular’, ‘book’, ‘medium’, ‘roman’, ‘semibold’,
156+
# ‘demibold’, ‘demi’, ‘bold’, ‘heavy’, ‘extra bold’, ‘black’
157+
weight = obj.get_weight()
158+
if weight in [
159+
'semibold', 'demibold', 'demi', 'bold', 'heavy', 'extra bold',
160+
'black'
161+
] or (isinstance(weight, int) and weight > 550):
154162
style.append('\\bfseries')
155163

164+
# \lfseries isn't that common yet
165+
# elif weight == 'light' or (isinstance(weight, int) and weight < 300):
166+
# style.append('\\lfseries')
167+
156168
if obj.axes:
157169
# If the coordinates are relative to an axis, use `axis cs`.
158170
tikz_pos = '(axis cs:%.15g,%.15g)' % pos

setup.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
# -*- coding: utf-8 -*-
22
#
3-
from setuptools import setup
4-
import os
53
import codecs
4+
import os
5+
6+
from setuptools import setup, find_packages
67

78
# https://packaging.python.org/single_source_version/
89
base_dir = os.path.abspath(os.path.dirname(__file__))
910
about = {}
1011
with open(os.path.join(base_dir, 'matplotlib2tikz', '__about__.py'), 'rb') as f:
12+
# pylint: disable=exec-used
1113
exec(f.read(), about)
1214

1315

@@ -17,15 +19,15 @@ def read(fname):
1719
os.path.join(os.path.dirname(__file__), fname),
1820
encoding='utf-8'
1921
).read()
20-
except Exception:
22+
except IOError:
2123
content = ''
2224
return content
2325

2426

2527
setup(
2628
name='matplotlib2tikz',
2729
version=about['__version__'],
28-
packages=['matplotlib2tikz'],
30+
packages=find_packages(),
2931
url='https://github.com/nschloe/matplotlib2tikz',
3032
download_url='https://pypi.python.org/pypi/matplotlib2tikz',
3133
author=about['__author__'],

test/helpers.py

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,6 @@ def __init__(self, fig):
7171
print('=' * 70)
7272
print(e.output)
7373
print('=' * 70)
74-
if 'DISPLAY' not in os.environ:
75-
cmd = ['curl', '-sT', tikz_file, 'chunk.io']
76-
out = subprocess.check_output(
77-
cmd,
78-
stderr=subprocess.STDOUT
79-
)
80-
print('Uploaded TikZ file to %s' % out.decode('utf-8'))
8174
raise
8275

8376
pdf_file = tmp_base + '.pdf'
@@ -121,35 +114,6 @@ def get_details(self):
121114

122115
print('pdftoppm output:')
123116
print(self.ptp_out.decode('utf-8'))
124-
125-
if 'DISPLAY' not in os.environ:
126-
# upload to chunk.io if we're on a headless client
127-
out = subprocess.check_output(
128-
['curl', '-sT', self.mpl_reference, 'chunk.io'],
129-
stderr=subprocess.STDOUT
130-
)
131-
print(
132-
'Uploaded reference matplotlib PDF file to %s' %
133-
out.decode('utf-8')
134-
)
135-
136-
out = subprocess.check_output(
137-
['curl', '-sT', self.tikz_file, 'chunk.io'],
138-
stderr=subprocess.STDOUT
139-
)
140-
print('Uploaded TikZ file to %s' % out.decode('utf-8'))
141-
142-
out = subprocess.check_output(
143-
['curl', '-sT', self.pdf_file, 'chunk.io'],
144-
stderr=subprocess.STDOUT
145-
)
146-
print('Uploaded output PDF file to %s' % out.decode('utf-8'))
147-
148-
out = subprocess.check_output(
149-
['curl', '-sT', self.png_file, 'chunk.io'],
150-
stderr=subprocess.STDOUT
151-
)
152-
print('Uploaded output PNG file to %s' % out.decode('utf-8'))
153117
return
154118

155119

test/test_image_plot.py

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,51 @@
11
# -*- coding: utf-8 -*-
22
#
33
import helpers
4+
5+
import matplotlib.pyplot as plt
46
import pytest
57

68
# the picture 'lena.png' with origin='lower' is flipped upside-down.
79
# So it has to be upside-down in the pdf-file as well.
810

911

10-
# test for monochrome picture
11-
def plot1():
12+
def plot_upper():
1213
from matplotlib import rcParams
13-
import matplotlib.pyplot as plt
14-
from PIL import Image
14+
import matplotlib.image as mpimg
1515
import os
1616

1717
this_dir = os.path.dirname(os.path.realpath(__file__))
18-
lena = Image.open(os.path.join(this_dir, 'lena.png'))
19-
lena = lena.convert('L')
18+
img = mpimg.imread(os.path.join(this_dir, 'lena.png'))
19+
2020
dpi = rcParams['figure.dpi']
21-
figsize = lena.size[0]/dpi, lena.size[1]/dpi
21+
figsize = img.shape[0]/dpi, img.shape[1]/dpi
2222
fig = plt.figure(figsize=figsize)
2323
ax = plt.axes([0, 0, 1, 1], frameon=False)
2424
ax.set_axis_off()
25-
plt.imshow(lena, cmap='viridis', origin='lower')
25+
26+
plt.imshow(img, cmap='viridis', origin='upper')
27+
2628
# Set the current color map to HSV.
2729
plt.hsv()
2830
plt.colorbar()
2931
return fig
3032

3133

32-
# test for rgb picture
33-
def plot2():
34+
def plot_lower():
3435
from matplotlib import rcParams
35-
import matplotlib.pyplot as plt
36-
from PIL import Image
36+
import matplotlib.image as mpimg
3737
import os
3838

3939
this_dir = os.path.dirname(os.path.realpath(__file__))
40-
lena = Image.open(os.path.join(this_dir, 'lena.png'))
40+
img = mpimg.imread(os.path.join(this_dir, 'lena.png'))
41+
4142
dpi = rcParams['figure.dpi']
42-
figsize = lena.size[0] / dpi, lena.size[1] / dpi
43+
figsize = img.shape[0] / dpi, img.shape[1] / dpi
44+
4345
fig = plt.figure(figsize=figsize)
4446
ax = plt.axes([0, 0, 1, 1], frameon=False)
4547
ax.set_axis_off()
46-
plt.imshow(lena, cmap='viridis', origin='lower')
48+
plt.imshow(img, cmap='viridis', origin='lower')
4749
# Set the current color map to HSV.
4850
plt.hsv()
4951
plt.colorbar()
@@ -52,11 +54,16 @@ def plot2():
5254

5355
@pytest.mark.parametrize(
5456
'plot, reference_phash', [
55-
(plot1, '455361ec211d72fb'),
56-
(plot2, '7558d3b30f634b06'),
57+
(plot_upper, '75c3d36d1f090ba1'),
58+
(plot_lower, '7548d3b34f234b07'),
5759
]
5860
)
5961
def test(plot, reference_phash):
6062
phash = helpers.Phash(plot())
6163
assert phash.phash == reference_phash, phash.get_details()
6264
return
65+
66+
67+
if __name__ == '__main__':
68+
plot_upper()
69+
plt.show()

test/test_legend_best_location.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,5 +62,5 @@ def plot():
6262

6363
def test():
6464
phash = helpers.Phash(plot())
65-
assert phash.phash == '879d990d0e8f7c1c', phash.get_details()
65+
assert phash.phash == '971d991d1c877c1c', phash.get_details()
6666
return

0 commit comments

Comments
 (0)