[Question]
  [
## Challenge
Given an input of an integer, \$n\$ (where \$0<n<50\$), output the graph of \$y=\mathrm{Re}((-n)^x)\$ from \$x = -3\$ to \$x = 3\$ inclusive.
Where \$\mathrm{Re}(p)\$ is the real part of the complex number \$p\$.
Note that \$\mathrm{Re}((-n)^x) = n^x \cos{(\pi x)}\$
## Output
The output may be in any form you wish (e.g. an image or a window etc.). ASCII art is disallowed.
The graph does not need to have axes (to allow languages without built-in graphing functions to compete).
If an image is output, it each side must be longer than 500 pixels. Similarly, the plot must fill the image as best it can.
The minimum interval between plots is 0.05.
Vector graphics are allowed.
## Examples
For an input of `2`:
![](https://i.stack.imgur.com/Vpryc.gif)
For an input of `1`:
![](https://i.stack.imgur.com/qpTPE.gif)
---
***You must put your corresponding outputs in your answer (n = 1 and n = 2).***
## Winning
The shortest code in bytes wins.
  
[Answer]
# TI-Basic, ~~26~~ 21 bytes
```
~3→Xmin
3→Xmax
Prompt N
DrawF N^Xcos(πX
```
Output for N=2:
[![TI84SE GRAPH OUTPUT](https://i.stack.imgur.com/T8PXX.png)](https://i.stack.imgur.com/T8PXX.png)
[Answer]
# Bash + Gnuplot, ~~56~~ 45 bytes
*(-11 bytes thanks to Noiralef!)*
```
gnuplot -e "se t png;p[-3:3]real((-$1)**x)">A
```
Saves the resulting graph as a `png` image named `A` in the current working directory. 
### Example Outputs
For **n = 1**:
![](https://i.stack.imgur.com/1bvil.png)
For **n = 2**:
![](https://i.stack.imgur.com/aA18z.png)
[Answer]
# [Python 3](https://docs.python.org/3/) with [matplotlib](https://matplotlib.org/), ~~103~~ 72 bytes
-12 bytes thanks to DSM (a module is installed alongside `matplotlib` called `pylab` with the necessary functionality "making Python in a repl more like Matlab" - odd, but true!)  
-18 more as a result (pylab has many numpy functions too!)  
-1 byte thanks to Ajasja (replacing `arange(-60,61)/20+0j` with `arange(121)/20-3+0j`)
```
from pylab import*
def f(n):x=arange(121)/20-3+0j;plot(x,(-n)**x);show()
```
**n=2,1**
![n=2](https://i.stack.imgur.com/dXoTS.png)
![n=1](https://i.stack.imgur.com/5IuLv.png)
[Answer]
# MATL, ~~22 18~~ 16 bytes
Thanks @LuisMendo for additional -2 bytes!
```
I_.01I3$:i_y^&XG
I_                       push 3 and negate         
  .01                    push 0.01
     I                   push 3  
      3$:                generate the list [-3,-2.99,-2.98,...,3]                        
         i_y^            calculate (-input)^(list)                 
             $XG         plot the first list against the real part of the second list
```
[Try it on matl.io](https://matl.io/?code=I_.01I3%24%3Ai_y%5E%26XG&inputs=2&version=19.9.0)
[Answer]
## Mathematica, 41 bytes
```
Plot[Re[(-#)^x],{x,-3,3},PlotRange->All]&
```
Output looks exactly as shown in the challenge except for the font of the numbers (which I suspect was created with Wolfram Alpha).
[Answer]
## R, 29 bytes
```
curve(Re((0i-scan())^x),-3,3)
```
`n` is provided through stdin.
Result for n=1:
[![enter image description here](https://i.stack.imgur.com/EJyeC.png)](https://i.stack.imgur.com/EJyeC.png)
And for n=2:
[![enter image description here](https://i.stack.imgur.com/RFBiL.png)](https://i.stack.imgur.com/RFBiL.png)
[Answer]
# MATLAB, ~~35~~ 30 bytes
```
x=-3:.01:3;@(n)plot(x,(-n).^x)
```
This defines an anyonmous function. The output is via a new window with a resizable vector graphic output. MATLAB's `plot` automatically ignores the imaginary part of the y-coordinates as long as your provide corresponding x-coordinates.The following output is for `n=3`.
![](https://i.stack.imgur.com/ljZ5y.jpg)
[Answer]
# R, 30 bytes
```
plot(Re((0i-n)^seq(-3,3,.05)))
```
### `n` = 1
[![enter image description here](https://i.stack.imgur.com/XVqu3.png)](https://i.stack.imgur.com/XVqu3.png)
### `n` = 2
[![enter image description here](https://i.stack.imgur.com/w38G9.png)](https://i.stack.imgur.com/w38G9.png)
[Answer]
# Excel VBA, ~~168~~ ~~160~~ ~~147~~ 138 Bytes (cells as pixels at 100x scale)
Saved 8 bytes thanks to KyleKanos  
Saved 22 bytes thanks to Taylor Scott
```
Sub g(n)
For i=0To 1
For x=-3To 3Step.01
y=n^x*Cos([Pi()]*x)
m=IIf(y<m,y,m)
If i Then Cells(500*(1-y/m)+1,(x+3)*100+1)="#
Next x,i
End Sub
```
Formatted, it looks like this:
```
Sub g(n)
    For i = 0 To 1
    For x = -3 To 3 Step 0.01
        y = n ^ x * Cos([Pi()] * x)
        m = IIf(y < m, y, m)
        If i Then Cells(500 * (1 - y / m) + 1, (x + 3) * 100 + 1) = "#"
    Next x, i
End Sub
```
Fun Fact: VBA does not have a built-in `pi` variable so we have to evaluate it as a worksheet function where it *does* exist.
**n=1**                                                                         **n=2**  
[![n=1](https://i.stack.imgur.com/8QcDD.png)](https://i.stack.imgur.com/8QcDD.png)     [![n=2](https://i.stack.imgur.com/9iQak.png)](https://i.stack.imgur.com/9iQak.png)
---
I started with a chart version at 193 bytes but it *did* get prettier results.
```
Sub c(n)
For x=-3To 3Step 0.05
r=r+1
Cells(r,1)=n^x*Cos(Atn(1)*4*x)
Next
With ActiveSheet.Shapes.AddChart(xlLine).Chart
.SetSourceData Range("A1:A121")
.Axes(xlCategory).Delete
End With
End Sub
```
**n=1**  
[![n=1](https://i.stack.imgur.com/AVSLR.png)](https://i.stack.imgur.com/AVSLR.png)  
**n=2**  
[![n=2](https://i.stack.imgur.com/GOxw3.png)](https://i.stack.imgur.com/GOxw3.png)
[Answer]
# MATLAB, ~~35~~ 33 bytes
*Thanks fo @flawr for removing 2 bytes!*
```
@(n)ezplot(@(x)real((-n)^x),-3:3)
```
This defines an anonymous function. To call it with input `2`, use `ans(2)` (or assign the function to a variable such as `f` and then use `f(2)`).
Output is vector graphics (resizable window). The sampling interval on the *x* axis is determined automatically by the `ezplot` function, but it seems to be more than enough.
A warning is produced in STDERR because the function passed to `ezplot` (`@(x)real((-n)^x)`) is not vectorized, but the graph is generated.
Example for `n = 2`:
[![enter image description here](https://i.stack.imgur.com/YoMZ1.png)](https://i.stack.imgur.com/YoMZ1.png)
[Answer]
# [Jupyter notebook](https://jupyter.org/) and Python 3; 53 bytes
```
%pylab
def f(n):x=arange(121)/20-3+0j;plot(x,(-n)**x)
```
Three bytes saved thanks to @Jonathan Allan.
[![n=1](https://i.stack.imgur.com/ixRfC.png)](https://i.stack.imgur.com/ixRfC.png)
[![n=2](https://i.stack.imgur.com/b0zV3.png)](https://i.stack.imgur.com/b0zV3.png)
[Answer]
# [Julia](http://julialang.org/) 0.6 with Plots.jl, 46 bytes
```
using Plots
~n=plot(real((0im-n).^(-3:.05:3)))
```
[![GR plot](https://i.stack.imgur.com/a2Mmk.png)](https://i.stack.imgur.com/a2Mmk.png)
This needed a Julia representation! 
Not much to golf here though, except (ab)using operator overloading to save bytes on function defintion, and using `0im-n` to make the input number complex where I might usually have used `Complex(n)`. That's necessary because in Julia, for [type stability](https://en.wikibooks.org/wiki/Introducing_Julia/Types#Type_stability) reasons, the `^` operator returns Complex results only when the input is Complex itself. So here we make it a complex number by adding `0im` ie. 0i. 
One cool thing about the Plots.jl package is that it automatically chooses the backend to use based on what plotting packages you have installed and where you're running the `plot` command from. The above plot was created with the [GR](https://github.com/jheinen/GR.jl) backend, but if I didn't have that installed (or if I explicitly ran a `plotly()` command like I did for this), it would have used the more interactive Plotly backend and output this (which looks a tiny bit nicer IMO):
[![Plotly plot](https://i.stack.imgur.com/SIlBy.png)](https://i.stack.imgur.com/SIlBy.png)
There's even a [UnicodePlots](https://github.com/Evizero/UnicodePlots.jl) backend, to print a plot in the terminal (or save to a text file) using Unicode characters and color codes. SE keeps messing up the plot alignment if I try to directly paste it though, so here's a terminal screenshot:
[![UnicodePlots plot](https://i.stack.imgur.com/b8FRJ.png)](https://i.stack.imgur.com/b8FRJ.png)
PS: The alternate formula, \$ Re((−n)^x)=n^xcos(πx) \$, comes out to the same length: 
```
using Plots
~n=plot(n.^(x=-3:.05:3).*cospi(x))
```
[Answer]
# [J](http://jsoftware.com/), ~~37~~ 36 bytes
Thanks to my colleague Marshall for guidance. -2 thanks to FrownyFrog.
Anonymous tacit prefix function.
```
-(]plot@;9 o.^)i:@3j120[load@'plot'
```
[![Plot window](https://i.stack.imgur.com/ljYn1.png)](https://i.stack.imgur.com/ljYn1.png)
```
-(]plot@;9 o.^)i:@3j120[load@'plot'
                        load@'plot'       NB. load plotting library
               i:@3j120                   NB. -3...3 in 120 steps
-                                         NB. negate argument
 (           ^)                           NB. raise the negated value to those exponents
 (       9 o. )                           NB. real part
 (]     ;     )                           NB. pair with the exponents
 ( plot@      )                           NB. plot it
```
[Answer]
# Desmos, ~~12~~ ~~10~~ 9 bytes
-2 thanks to @Steffan  
-1 thanks to @LeoDog896
```
n^xcosxπ
```
How has nobody used Desmos yet?
[Answer]
# Encapsulated PostScript; 232 bytes
```
%!PS-Adobe-3.0 EPSF-3.0
%%BoundingBox: 0 0 500 500
%%EndComments
/n 1 def .02 setlinewidth /f{dup dup n exch exp exch 180 mul cos mul 3 div}def
250 250 translate 80 80 scale newpath -3 f moveto -3 .05 3{f lineto}for stroke
%%EOF
```
Now since this is a vector image itself... 
[![enter image description here](https://i.stack.imgur.com/us3SR.png)](https://i.stack.imgur.com/us3SR.png)
[![enter image description here](https://i.stack.imgur.com/fYp2i.png)](https://i.stack.imgur.com/fYp2i.png)
[Answer]
# [TikZ](https://www.ctan.org/pkg/pgf?lang=en) + [PGFPlots](https://www.ctan.org/pkg/pgfplots?lang=en), 175 bytes
```
\documentclass{standalone}\usepackage{tikz,pgfplots}\begin{document}\typein[\n]{}\tikz{\begin{axis}\addplot[domain=-3:3,samples=120]{\n^x*cos(180*x)};\end{axis}}\end{document}
```
Compile with, *e.g.*, `latexmk -cd -f -pdf in.tex` for a pdf output. During compilation, the user is prompted for `n`.
Sample outputs (converted to png) for n = 1 and n = 2:
![n = 1](https://i.stack.imgur.com/CnqRc.png)
![n = 2](https://i.stack.imgur.com/Rda8B.png)
[Answer]
# [Math.JS Grapher](http://a-ta.co/grapher), 20 Bytes
```
r(n)=f(x)=re((-n)^x)
```
By sheer fluke, this graphing utility is TC (For the most part, Infinite loops just crash it.), and by nature, it's primary output is graphs.
## How it works
`r(n)=` assigns a function `r` which takes the argument `n` to the expression `f(x)=re((-n)^x)`. `re((-n)^x)` is pretty much letter for letter the challenge description. But this assigns the function `f(x)` to this, which the grapher implicitly outputs as a line graph.
## How to test it
You can use [this](http://a-ta.co/grapher) site, punch that function in there, then call it with `r(input)`.
## Output
![Output](https://i.stack.imgur.com/gnKgV.png)
[Answer]
# Dyalog APL, 41 bytes
```
⎕SE.UCMD∊'chart x(9○(-'⍞')*x←3-20÷⍨⍳121)'
```
### How it works:
```
⎕SE.UCMD∊'chart x(9○(-'⍞')*x←3-20÷⍨⍳121)' ⍝ Main function
⎕SE.UCMD∊                                 ⍝ User Command (called from the session object)
         'chart                           ⍝ Plot a chart with arguments:
                 (           3-20÷⍨⍳121)' ⍝ Yields the list [-3, -2.95, -2.9,..., 2.9, 2.95, 3]
                           x←             ⍝ Assign that list to x
                          *               ⍝ and use it as exponent
                    (-'⍞')                ⍝ with (-input) as base
                  9○                      ⍝ discard the complex part; this generates Re((-n)^x)
                x                         ⍝ And x.
```
The user command `]chart`, in this case, takes two vector arguments, `x` and `y` and plots the graphs:
For \$n=1\$:
[![n=1](https://i.stack.imgur.com/ulaLx.png)](https://i.stack.imgur.com/ulaLx.png)
For \$n=2\$:
[![n=2](https://i.stack.imgur.com/ZpbW6.png)](https://i.stack.imgur.com/ZpbW6.png)
[Answer]
# Excel VBA, 133 bytes
Immediate window script that takes input from `[A1]` and outputs a `Chart` object to the `Sheet1` object.
```
[B:B]="=ROW()/20-3.05":[C:C]="=A$1^B1*Cos(Pi()*B1)":Set c=Sheet1.Shapes.AddChart(4).Chart:c.SetSourceData[C1:C121]:c.Axes(1).Delete
```
## Ungolfed
Full `Sub`routine version. I/O is unchanged.
```
Sub b()
    [B:B] = "=ROW()/20-3.05"                ''  Define `x`-axis
    [C:C] = "=A$1^B1*Cos(Pi()*B1)"          ''  Define `y`-axis in terms of input from A1
    Set c = Sheet1.Shapes.AddChart(4).Chart ''  Add line plot to Sheet1 (xlLine)
    c.SetSourceData [C1:C121]               ''  Set `y` source to match `x` in [-3,3]
    c.Axes(1).Delete                        ''  Remove erroneous axes (xlCategory)
End Sub
```
## Output
Where input, \$n=1\$
[![Output plot n=1](https://i.stack.imgur.com/e5jva.png)](https://i.stack.imgur.com/e5jva.png)
Where input, \$n=3\$
[![Output plot n=3](https://i.stack.imgur.com/Babmi.png)](https://i.stack.imgur.com/Babmi.png)
[Answer]
# Google Sheets, 65
* Input N is in A1
Graphing:
* `=SPARKLINE(ArrayFormula(IMREAL(IMPOWER(-A1,.05*SEQUENCE(121,1,-60`
or
* `=SPARKLINE(ArrayFormula(IMREAL(IMPOWER(-A1,SEQUENCE(121,1,-60)/20`
Resize row and column of graph to 500x500.
I tried to use the COS() formula, but the best I can do is 66 characters with a named range. Problems that I came across:
* X is generated by the SEQUENCE(), which is then used twice. You would naturally think to cache this, but every time you cache into a column, to use it again, you have to either name a range, or use a FILTER. Named Range is obviously better, but it does cost 1 character to make it fair.
* Attempting to scalar multiply a SEQUENCE() forces us into an ArrayFormula (or MMULT() at best), and we cannot use a non-integer step for SEQUENCE(). This means that the most optimal way to use it is to give it to the SPARKLINE formula.
* This also means that our scalar multiply/divide has to occur each time we use the range.
[Answer]
# SmileBASIC, 82 bytes
```
INPUT N
FOR I=0TO 399X=I/66.5-3GPSET I,120-POW(N,X-3*SGN(N-1))*COS(PI()*X)*120NEXT
```
Graph fills the entire screen, even when N is less than 1.
When N is greater than 1, you can scale Y to be between -1 and 1 by dividing it by `n^3`. I'm already doing `n^x`, and `n^x / n^3` can be simplified to `n^(x-3)`. However, when N is less than 1, I have to divide Y by `n^-3` instead. This is equivalent to `n^(x+3)`.
I can use `n^(x-3*sign(n-1))` to use `-3` if `n>1`, and `+3` if `n<1`
Images coming soon
]