Skip to main content

plotting - Graphics plot of point using unfilled circle



I'd like to be able to place points on a plot using Graphics[{Point[{a,b}],....}] but have the plot symbol be an unfilled circle. I've looked around but can't find any way of doing this. Is there one? Thanks.


After reading the first response, perhaps I should add a bit more. I'd like to be able to do the following:


p1 = Plot[x^2,{x,-3,3}]
p2 = Graphics[Style[Point[{0,0}],PointSize[Large]]
Show[p1,p2]

but with an unfilled circle instead of a dot.


The solution proposed in the first answer falls short in two ways: first, the unfilled circle does not properly hide graphics elements underneath it; second, the circle will appear as an ellipse, not a circle, in the (likely) event that the underlying graphic does not have aspect ratio 1.


The application here is for plotting piecewise discontinuous functions and showing clearly which endpoint at a jump discontinuity holds the value at the point.



Answer




The purpose of the circles is to mark discontinuities, but if I understand you correctly you don't want exactly the same as in this linked question where the ExclusionsStyle option is discussed. You want the circles to sit only on one side of a discontinuity to indicate which side holds the value.


I'll compare that to the ExclusionsStyle method here. If you do use that option, it is possible to replace the default Point markers by anything you want using a replacement rule after the plot has been drawn:


With[{pointSize = .1},
Plot[
Floor[x], {x, -3, 3}, Background -> LightGray,
ExclusionsStyle -> {None, {}}] /. Point[x_] :> Map[
Inset[
Graphics[
{EdgeForm[Black], Cyan, Disk[]}
],

#, Automatic, pointSize] &,
x
]
]

ExclusionsStyle


So what I did here is to specify a dummy ExclusionsStyle with an empty list {} where the point style directive would normally go, just to make Mathematica draw Points at the discontinuities in the first place.


Then I replace every occurrence of Point by an Inset containing the desired outlined disk (I colored it cyan for clarity here). The Inset is positioned where the Point coordinates would have been. The Map is used to take into account the fact that Point has a whole list of coordinates as its argument, and a new Inset has to replace each of these.


As I said, this may not be what you need because it marks both sides of the discontinuity equally.


An alternative would be to not use ExclusionsStyle, as you already suggest in the question. But instead of using Graphics to make the points, I would suggest to use ListPlot. Not only is it specially designed to do just such point sets, but moreover it is relatively straightforward to pass it arbitrary symbols or graphics as markers for the points:



With[{markerSize = .03},
Show[
Plot[Floor[x], {x, -3, 3},
PlotStyle -> Thick],
ListPlot[
Table[{i, i}, {i, -3, 3}],
PlotMarkers -> {
Graphics[
{EdgeForm[Black],
Yellow, Disk[]}

], markerSize
}
],
Background -> LightGray
]
]

ListPlot


Here, the Table contains the points I want to mark, and that allows me to exclude one side of each discontinuity. Here I chose a yellow disk for clarity.


Edit



By using ListPlot with the points collected in a Table, one also has the flexibility to add differently styled points to mark the two sides of a discontinuity separately - something which is much harder to do within the framework of ExclusionsStyle:


With[{markerSize = .03}, Show[
Plot[Floor[x], {x, -3, 3}, PlotStyle -> Thick],
ListPlot[{
Table[{i, i}, {i, -3, 3}],
Table[{i + 1, i}, {i, -3, 3}]},
PlotMarkers -> {
{Graphics[{EdgeForm[Black], Yellow, Disk[]}], markerSize},
{Graphics[{EdgeForm[Black], Red, Disk[]}], markerSize}
}

],
Background -> LightGray]
]

Better exclusion marking


Comments

Popular posts from this blog

plotting - How to draw lines between specified dots on ListPlot?

I would like to create a plot where I have unconnected dots and some connected. So far, I have figured out how to draw the dots. My code is the following: ListPlot[{{1, 1}, {2, 2}, {3, 3}, {4, 4}, {1, 4}, {2, 5}, {3, 6}, {4, 7}, {1, 7}, {2, 8}, {3, 9}, {4, 10}, {1, 10}, {2, 11}, {3, 12}, {4,13}, {2.5, 7}}, Ticks -> {{1, 2, 3, 4}, None}, AxesStyle -> Thin, TicksStyle -> Directive[Black, Bold, 12], Mesh -> Full] I have thought using ListLinePlot command, but I don't know how to specify to the command to draw only selected lines between the dots. Do have any suggestions/hints on how to do that? Thank you. Answer One possibility would be to use Epilog with Line : ListPlot[ {{1, 1}, {2, 2}, {3, 3}, {4, 4}, {1, 4}, {2, 5}, {3, 6}, {4, 7}, {1, 7}, {2, 8}, {3, 9}, {4, 10}, {1, 10}, {2, 11}, {3, 12}, {4, 13}, {2.5, 7}}, Ticks -> {{1, 2, 3, 4}, None}, AxesStyle -> Thin, TicksStyle -> Directive[Black, Bold, 12], Mesh -> Full, Epilog -> { Line[ ...

equation solving - Invert and fit implicitly defined curve

I need to fit an implicitly defined curve. I thought I could get some data out of Solve , and then using FindFit . Therefore, I would like to find the relation the parametric curve defined by $F(x,y)=0$: Solve[-(1/2) + 1/2 (0.41202 BesselK[0, 0.1 Sqrt[x^2 + y^2]] + (0.101483 x BesselK[1, 0.1 Sqrt[x^2 + y^2]])/Sqrt[x^2 + y^2]) == 0, y] But I can't get an output: Solve was unable to solve the system with inexact coefficients or the system obtained by direct rationalization of inexact numbers present in the system. Since many of the methods used by Solve require exact input, providing Solve with an exact version of the system may help. >> Edit: In particular, I would like to fit the data coming from the curve with the expression of another curve, and not with a function $f(x)$. In particular, since this clearly looks like a cardioid , I would like it to fit to something like it. What other strategies could I try?

dynamic - How can I make a clickable ArrayPlot that returns input?

I would like to create a dynamic ArrayPlot so that the rectangles, when clicked, provide the input. Can I use ArrayPlot for this? Or is there something else I should have to use? Answer ArrayPlot is much more than just a simple array like Grid : it represents a ranged 2D dataset, and its visualization can be finetuned by options like DataReversed and DataRange . These features make it quite complicated to reproduce the same layout and order with Grid . Here I offer AnnotatedArrayPlot which comes in handy when your dataset is more than just a flat 2D array. The dynamic interface allows highlighting individual cells and possibly interacting with them. AnnotatedArrayPlot works the same way as ArrayPlot and accepts the same options plus Enabled , HighlightCoordinates , HighlightStyle and HighlightElementFunction . data = {{Missing["HasSomeMoreData"], GrayLevel[ 1], {RGBColor[0, 1, 1], RGBColor[0, 0, 1], GrayLevel[1]}, RGBColor[0, 1, 0]}, {GrayLevel[0], GrayLevel...