przemekk
przemekk

Reputation: 361

matplotlib.pyplot theta grid thickness

I have some trouble formatting polar graph theta grid. The most outer circle seems to be thiner than the others, is there any way to correct it? I've noticed that removing set_rmax solves the issue but causes to radius grid lines goes outside the circle - I don't want it. Code sample below.

#!/usr/bin/python3
# -*- coding: utf-8 -*-

import matplotlib.pyplot as plt
import numpy as np

fig = plt.figure()
ax = fig.add_axes([0, .15, 1, .75],
                  frameon=False,
                  projection='polar',
                  rlabel_position=22.5,
                  theta_offset=(-np.pi / 2))
theta = list(map(lambda x: x * np.pi / 180,
                 [i for i in range(0, 360, 15)]))
values = [i for i in range(0, 24)]
values2 = [i for i in range(24, 0, -1)]

ax.plot(theta, values, label='zzz')
ax.plot(theta, values2, label='xxx')
ax.set_rticks([i * 24 / 4 for i in range(0, 5)])
ax.set_yticklabels([])
ax.set_thetagrids(angles=[0, 30, 60, 90, 120, 150, 180,
                          210, 240, 270, 300, 330],
                  labels=list(map(lambda x: str(x)
                                  + u'\N{DEGREE SIGN}',
                                  [0, 30, 60, 90, 120, 150, 180])))
fig.legend(frameon=False,
           loc='lower left',
           ncol=1)

ax.set_rmax(24)
plt.show()

Upvotes: 1

Views: 1063

Answers (1)

ImportanceOfBeingErnest
ImportanceOfBeingErnest

Reputation: 339220

You turned the frame of the polar plot off. Hence the outmost circle isn't even shown. Turning the frame on again, and setting the color of the outer circle to grey would give you the desired result.

import matplotlib.pyplot as plt
import numpy as np

fig = plt.figure()
ax = fig.add_axes([0, .15, 1, .75],
                  frameon=True,
                  projection='polar',
                  rlabel_position=22.5,
                  theta_offset=(-np.pi / 2))
theta = list(map(lambda x: x * np.pi / 180,
                 [i for i in range(0, 360, 15)]))
values = [i for i in range(0, 24)]
values2 = [i for i in range(24, 0, -1)]

ax.plot(theta, values, label='zzz')
ax.plot(theta, values2, label='xxx')
ax.set_rticks([i * 24 / 4. for i in range(0, 5)])
ax.set_yticklabels([])
ax.set_thetagrids(angles=[0, 30, 60, 90, 120, 150, 180,
                          210, 240, 270, 300, 330],
                  labels=list(map(lambda x: str(x)
                                  + u'\N{DEGREE SIGN}',
                                  [0, 30, 60, 90, 120, 150, 180])))
fig.legend(frameon=False,
           loc='lower left',
           ncol=1)

ax.set_rmax(24)
ax.spines["polar"].set_color(plt.rcParams["grid.color"])
ax.spines["polar"].set_linewidth(plt.rcParams["grid.linewidth"])

plt.show()

enter image description here

Upvotes: 1

Related Questions