In some rooms if you are last to act on an all in you can show your cards.
If you are last in with a call or raise I don't think you can show.
Some times it has to be heads up, last to act, and all in.
If there are any players who will act behind you, no. It is unfair to the other players to give your opponent information that might affect them.
In a tournament, no. It is unfair to use this advantage that players acting before you didn't have.
In a cash game if you are head-up, or last to act with all other players all-in, some clubs will allow showing cards, as this is not unethical or unfair in this situation. Ask your floorman.