2

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.

4
  • Which library are you using? (Matplotlib?) What’s the error? How are you attempting to make this change? Commented 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. Commented Apr 11, 2015 at 1:29
  • Okay I think the only way is for me to post the code and then the error: Commented 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! Commented Apr 11, 2015 at 1:42

2 Answers 2

3

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.

Sign up to request clarification or add additional context in comments.

Comments

3

See the list of valid kwargs on the Circle documentationlinestyle can be one of solid, dashed, dashdot, or dotted.

circ = plt.Circle((x,y), R, linestyle='dashed', edgecolor='b', facecolor='none')

6 Comments

I have just tried that, but there is still no line showing
@StormHayward: Does it show up if you set a facecolor? What are the values of x, y, and R?
No it doesn't. x=71.42, y=0, R=118.5
I have read another code and they had added: ax.add_patch(circ) and it works. However, I don't actually understand why it works and what patches are.
@StormHayward: A patch is an object you add to the plot. plt.Circle is just a constructor for the patch and doesn’t add anything by itself.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.