rougier / scientific-visualization-book

An open access book on scientific visualization using python and matplotlib
https://www.labri.fr/perso/nrougier/
Other
10.66k stars 986 forks source link

Code for Figure 2.3 from the book doesn't match the image (Chapter 2, pages 22-23) #65

Closed labdmitriy closed 2 years ago

labdmitriy commented 2 years ago

Hi @rougier,

If we use the code for the Figure 2.3 from the book, then the border will be inside data coordinates, not outside as expected, and with different tick labels (specifying the code from the book before resolving #63):

fig = plt.figure(figsize=(5, 5), dpi=100)
ax = fig.add_subplot(1, 1, 1, projection='polar')

FC_to_DC = ax.transData.inverted().transform
NDC_to_FC = ax.transAxes.transform
NDC_to_DC = lambda x: FC_to_DC(NDC_to_FC(x))

P = NDC_to_DC([[0,0], [1,0], [1,1], [0,1], [0,0]])

plt.plot(P[:,0], P[:,1], clip_on=False, zorder=-10
         color="k", linewidth=1.0, linestyle="--", )
plt.scatter(P[:-1,0], P[:-1,1],
            clip_on=False, facecolor="w", edgecolor="k")
plt.show()

But the code in Python file is correct. I compared the code and find that for displaying the figure there are 2 additional lines in Python file: https://github.com/rougier/scientific-visualization-book/blob/a8eeebb08d443caba6b1ad4d9b18e4a449a41f06/code/coordinates/transforms-polar.py#L12 https://github.com/rougier/scientific-visualization-book/blob/a8eeebb08d443caba6b1ad4d9b18e4a449a41f06/code/coordinates/transforms-polar.py#L30

And the first line (setting the limits for y-axis and specifying tick labels) is required to get expected figure.

Thank you.

rougier commented 2 years ago

Thanks, can you make a PR?