pyplot how to change bground color ?

218 views
Skip to first unread message

Henri Girard

unread,
Jun 24, 2016, 6:56:42 AM6/24/16
to julia-users
Hi,
I didn't find anything to modify background in pyplot, it's so easy in plots but that doesn't work for pyplot, even maplotlib command ?
Any help ?
HG

Tom Breloff

unread,
Jun 24, 2016, 7:50:15 AM6/24/16
to julia...@googlegroups.com
When you say "doesn't work for pyplot", what have you tried?

Henri Girard

unread,
Jun 26, 2016, 1:30:04 AM6/26/16
to julia-users
matplotlib commands
But it 's not very convivial, is there something
like bgroundcolor=("black"),often I don't use ax.

rect
.set_facecolor('red')

ax.patch.set_facecolor('black')
axisbg='#ababab'

Henri Girard

unread,
Jun 26, 2016, 6:02:33 AM6/26/16
to julia-users
Here is the way I found to do it but that's quiet heavy.
Plots it's so easy, but I don't convert ODE properly in julia.

const g  = 9.8                # Accelaration of gravity
const p  = 1.2                # Density of air

# Caracteristics of the problem
const m  = 0.100              # A 100 g ball
const r  = 0.10               # 10 cm radius
const Cd = 0.5                # Drag coeficient for a small spherical object
const y0 = 1000.0             # Initial height of the body (1000 m)
const v0 = 10.0               # Initial velocity of the body (10 m/s^2, going up)
const A  = pi*r^2;            # Cross-section area of the body;

function gm(t, f)
    (y, v) = f                                          # Extract y and v (i.e., dy/dt) from the f mapping
   
    dy_dt = v                                           # The differential equations
    dv_dt = -1.0*g - sign(v)*(1./2.)*(p/m)*Cd*A*v^2.0
   
    [dy_dt; dv_dt]                                      # Return the derivatives
end;
# Initial conditions (position and velocity)
const start = [y0; v0]

# Time span (from 0 to 5 secs)
ts = [0.0; 5.0];
t, res = ode45(gm, start, ts)
y = map(x -> x[1], res)
v = map(x -> x[2], res);
using PyPlot
fig, ax = subplots(1, 2, sharex=true,
figsize=(10,4), dpi=80)

ax[1][:plot](t, v)
ax[1][:set_axis_bgcolor]("red")
ax[1][:set_axis_bgcolor]((0.5, 0.5, 0.5))
ax[1][:set_title]("Velocity over time");
ax[1][:set_xlabel]("Time (sec)")
ax[1][:set_ylabel]("Velocity (m/sec)")

ax[2][:plot](t, y)
ax[2][:set_title]("Height over time");
ax[2][:set_xlabel]("Time (sec)")
ax[2][:set_ylabel]("Height (m)");


Le vendredi 24 juin 2016 12:56:42 UTC+2, Henri Girard a écrit :

Henri Girard

unread,
Jun 26, 2016, 7:29:22 AM6/26/16
to julia-users
Here is what I would like in ijulia it's in python, but I have problem to convert fig

%matplotlib inline

matplotlib.rcParams.update({'font.size': 12})
fig = matplotlib.pyplot.figure(figsize=(5,5),
                               dpi=300,
                               facecolor='black')
fig.subplots_adjust(wspace=.05,left=.01,
                    bottom=.01)
ax = fig.add_subplot(1,1,1,axisbg='k')

ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.spines['bottom'].set_linewidth(0.5)
ax.spines['left'].set_linewidth(0.5)
ax.spines['bottom'].set_color('white')
ax.spines['left'].set_color('white')

ax.title.set_color('white')
ax.yaxis.label.set_color('white')
ax.xaxis.label.set_color('white')
ax.tick_params(axis='x', colors='white')
ax.tick_params(axis='y', colors='white')

ax.tick_params(axis='both', direction='in')
ax.get_xaxis().tick_bottom()
ax.get_yaxis().tick_left()

ax.set_xlabel('X-Axis Label Here')
ax.set_ylabel('Y-Axis Label Here')
ax.set_title('Title Here')

ax.plot(range(10),range(10),'.-',color='yellow',\
  linewidth=2,\
  markersize=12)

matplotlib.pyplot.savefig("dark.png",\
  bbox_inches='tight',\
  facecolor=fig.get_facecolor(),\
  transparent=True)


Le vendredi 24 juin 2016 12:56:42 UTC+2, Henri Girard a écrit :
Reply all
Reply to author
Forward
0 new messages