I am currently trying to draw a circle in Python. However, the outline of the circle is not plotting. I have tried to change the linestyle, but an error is coming up.
-
Which library are you using? (Matplotlib?) What’s the error? How are you attempting to make this change?Ry-– Ry- ♦2015-04-11 01:21:54 +00:00Commented Apr 11, 2015 at 1:21
-
"The error is quite lengthy but..." That's fine, we've got plenty of space. Let's see it.Kevin– Kevin2015-04-11 01:29:01 +00:00Commented Apr 11, 2015 at 1:29
-
Okay I think the only way is for me to post the code and then the error:S Hayward– S Hayward2015-04-11 01:31:23 +00:00Commented Apr 11, 2015 at 1:31
-
I have posted the code. I am very new to programming so I can only apologise if it's a mess!S Hayward– S Hayward2015-04-11 01:42:33 +00:00Commented Apr 11, 2015 at 1:42
2 Answers
The inconsistency in line styles is in the process of being sorted out (https://github.com/matplotlib/matplotlib/pull/3772 ).
A lightning summary of mpl architecture: Figures have 1 or more Axes which have many Artists (subtle detail, Axes and Figure are actually sub-classes of Artist and Figure objects can have other Artists than just Axes). Figure objects also have a Canvas objects (of which there are many implementations for outputting to different formats (ex png, tiff, svg, pdf, eps, ...). When you draw the Figure there is some internal plumbing and each of the Artist objects are recursively drawn to the Canvas.
Most of the plt commands create an Artist and then add it to your current Axes (it pyplot has enough internal state to know what you current Axes is and create one if needed). However, Circle just creates and return a Patch object (which is a type of Artist). It is some what odd that Circle is directly exposed via the pyplot interface.
For this to work you will need to do something like
import matplotlib.pyplot as plt
import matplotlib.patches as mpatches
fig, ax = plt.subplots()
# note use Circle directly from patches
circ = mpatches.Circle((1, 0), 5, linestyle='solid', edgecolor='b', facecolor='none')
ax.add_patch(circ)
ax.set_xlim(-10, 10)
ax.set_ylim(-10, 10)
ax.set_aspect('equal')
Please follow PEP8, you will thank your self later.
Comments
See the list of valid kwargs on the Circle documentation – linestyle can be one of solid, dashed, dashdot, or dotted.
circ = plt.Circle((x,y), R, linestyle='dashed', edgecolor='b', facecolor='none')
6 Comments
facecolor? What are the values of x, y, and R?plt.Circle is just a constructor for the patch and doesn’t add anything by itself.