Skip to main content
fix a typo
Source Link
Brett Champion
  • 20.9k
  • 2
  • 65
  • 122

All the solutions so far have plotted {n, 2^Prime[n]} for integer values of n, which means that the points will be evenly spaced along the horizontal axis. Here's how to do what was actually asked, plotting {x, 2^x} for prime values of x.

Since 2^x grows so quickly, I'll demonstrate instead with Sqrt[x] so that it's easier to see the uneven distribution of primes along the horizontal axis.

  • Using ListPlot, you want to specify the horizontal position using {x,y} pairs, rather than just a list of heights:

      primes = Table[Prime[n], {n, 20}];
      ListPlot[Table[{x, Sqrt[x]}, {x, primes}]]
    

enter image description here

  • Using DiscretePlot, you want to provide the horizontal positions using the {x, {x1, x2, ..., xn}} variable specification:

      primes = Table[Prime[n], {n, 20}];
      DiscretePlot[Sqrt[x], {x, listprimes}]
    

enter image description here

All the solutions so far have plotted {n, 2^Prime[n]} for integer values of n, which means that the points will be evenly spaced along the horizontal axis. Here's how to do what was actually asked, plotting {x, 2^x} for prime values of x.

Since 2^x grows so quickly, I'll demonstrate instead with Sqrt[x] so that it's easier to see the uneven distribution of primes along the horizontal axis.

  • Using ListPlot, you want to specify the horizontal position using {x,y} pairs, rather than just a list of heights:

      primes = Table[Prime[n], {n, 20}];
      ListPlot[Table[{x, Sqrt[x]}, {x, primes}]]
    

enter image description here

  • Using DiscretePlot, you want to provide the horizontal positions using the {x, {x1, x2, ..., xn}} variable specification:

      primes = Table[Prime[n], {n, 20}];
      DiscretePlot[Sqrt[x], {x, list}]
    

enter image description here

All the solutions so far have plotted {n, 2^Prime[n]} for integer values of n, which means that the points will be evenly spaced along the horizontal axis. Here's how to do what was actually asked, plotting {x, 2^x} for prime values of x.

Since 2^x grows so quickly, I'll demonstrate instead with Sqrt[x] so that it's easier to see the uneven distribution of primes along the horizontal axis.

  • Using ListPlot, you want to specify the horizontal position using {x,y} pairs, rather than just a list of heights:

      primes = Table[Prime[n], {n, 20}];
      ListPlot[Table[{x, Sqrt[x]}, {x, primes}]]
    

enter image description here

  • Using DiscretePlot, you want to provide the horizontal positions using the {x, {x1, x2, ..., xn}} variable specification:

      primes = Table[Prime[n], {n, 20}];
      DiscretePlot[Sqrt[x], {x, primes}]
    

enter image description here

Source Link
Brett Champion
  • 20.9k
  • 2
  • 65
  • 122

All the solutions so far have plotted {n, 2^Prime[n]} for integer values of n, which means that the points will be evenly spaced along the horizontal axis. Here's how to do what was actually asked, plotting {x, 2^x} for prime values of x.

Since 2^x grows so quickly, I'll demonstrate instead with Sqrt[x] so that it's easier to see the uneven distribution of primes along the horizontal axis.

  • Using ListPlot, you want to specify the horizontal position using {x,y} pairs, rather than just a list of heights:

      primes = Table[Prime[n], {n, 20}];
      ListPlot[Table[{x, Sqrt[x]}, {x, primes}]]
    

enter image description here

  • Using DiscretePlot, you want to provide the horizontal positions using the {x, {x1, x2, ..., xn}} variable specification:

      primes = Table[Prime[n], {n, 20}];
      DiscretePlot[Sqrt[x], {x, list}]
    

enter image description here