2D Histogram

I need to plot the logistics map using a 2D histogram. My r will vary from 1 to 4.

I have used Gnuplot before, but I don't see a 2d histogram option.

Any suggestions? It does not have to be Gnuplot
Read the question and first few answers here:
https://stackoverflow.com/questions/2471884/histogram-using-gnuplot
Also consider python with matplotlib.

BTW what are you actually plotting? It seems an odd way to portray the logistic map.
Last edited on
I have to do it in C++. I was supposed to do it in CERN's ROOT, but I got permission to use any other C++ program.

I am doing the logistics map where r varies from 1 to 4 in 2000 steps. However, in each step, it will iterate 300 times. So, r= 1 will iterate 300 times, then 1.0005 will iterate 300 times etc. 6000 iterations.

The y axis will give me the calculation for each iteration, and the x axis will be r from 1 t 4.

I was supposed to drop this class, so I missed a few lectures, but they didn't drop me, so I have to figure all this out.

You can have a play with this.

In gnuplot you should be able to plot the output with just
p "logistic.out" u 1:2 w p
I don't know why you need histograms.


It bifurcates beautifully at about r=3, then again at about r=3.5, then goes on to quasi-chaos.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <iostream>
#include <iomanip>
#include <fstream>
#include <random>
#include <ctime>
using namespace std;

// Random number generator
mt19937 gen( time( 0 ) );
uniform_real_distribution<double> dist( 0.0, 1.0 );


double logistic( double r, double x, int n )
{
   for ( int i = 0; i < n; i++ ) x = r * x * ( 1.0 - x );
   return x;
}


int main()
{
   double r1 = 1, r2 = 4;            // limits on r
   int N = 6000;                     // number of intervals for r
   double dr = ( r2 - r1 ) / N;
   int niter = 300;                  // number of iterations for each r

   #define SP << fixed << setprecision( 6 ) << setw( 12 ) <<     // format of output
// ostream &out = cout;              // output to screen
   ofstream out( "logistic.out" );   // output to file

   out SP "r" SP "x_end" << '\n';    // header
   for ( int i = 0; i <= N; i++ )
   {
      double r = r1 + i * dr;        // growth rate 
      double x0 = dist( gen );       // random starting point in (0,1)
      out SP r SP logistic( r, x0, niter ) << '\n';
   }
}
Last edited on
First of all, that is amazing. Thank you.

To be honest, I have no idea why I needed a 2d histogram. In my head, I pictured something completely different. I was supposed to drop this class, but they wouldn't let me, so I missed lectures. I am going off of the professor's lecture notes.

Topic archived. No new replies allowed.