# Plot a function with a discrete part

I would like to plot a function like this one:

f[x_] = Piecewise[{{x, x ∈ Integers && x > 0}, {1/2, x < 0}}, Indeterminate]

DiscretePlot[f[x], {x, -2, 2}]

Plot[f[x], {x, -2, 2}]


When I use DiscretePlot I get only the first part and when I use Plot I get only the part with y = 1/2. How can I solve this?

• it works for me. can you provide your code. May 7 '15 at 15:16
• fro the DiscretePlot try AxesOrigin -> {0, 0}, for Plot, it is ok because Plot dose not do Discrete Plot May 7 '15 at 15:23
• When I add AxesOrigin -> {0, 0} to DiscretePlot, there are points (x, 1/2) where x is Integer, still it's not continuous May 7 '15 at 15:25
• DiscretePlot does not do continuous plotting. continuous can be done with Plot. but remember, your function when x>0 is not continues it is discrete (f[0.5] return Indeterminate) May 7 '15 at 15:28
• I know, and it is the most important for me, because I need to create a function in part discrete and in part continuous. But I have problem with plot May 7 '15 at 15:32

Show[Plot[f[x], {x, -2, 0}], 