/ / tworzenie podplotów, w tym wykresu słupkowego - python, wykres słupkowy, podplot

tworzenie podplotów zawierających wykres słupkowy - python, wykres słupkowy, wątek podrzędny

Chcę wykreślić 3 podtypy, przy czym pierwszy wykres tobar. Kiedy to robię, oś x przesuwa się w lewo. I mam bardzo dziwnie wyglądający wykres słupkowy, patrz rysunek poniżej. Jeśli zmienię „słupek” na „” wykres ”, to działa dobrze, ale wykres jest linią zamiast słupków.

wprowadź opis obrazu tutaj

kwargs=dict(delimiter="t",
skip_header=0,
missing_values="NaN",
converters={0:matplotlib.dates.strpdate2num("%d-%m-%Y %H:%M")},
dtype = float,
names=True,
)

storm_dis_cats = np.genfromtxt("C:UserskerDocumentsDischarge_data_Catsop_27-06-2014.txt",**kwargs)

kwargs=dict(delimiter="t",
skip_header=0,
missing_values="NaN",
converters={0:matplotlib.dates.strpdate2num("%d-%m-%Y %H:%M")},
dtype = float,
names=True,
)

storm_stage_cats = np.genfromtxt("C:UserskerDocumentsStageheight_data_Catsop_27-06-2014.txt",**kwargs)

kwargs=dict(delimiter="t",
skip_header=0,
missing_values="NaN",
converters={0:matplotlib.dates.strpdate2num("%d-%m-%Y %H:%M")},
dtype = float,
names=True,
)

storm_rain_cats = np.genfromtxt("C:UserskerDocumentsRainfall_data_Catsop_27-06-2014.txt",**kwargs)

discharge = storm_dis_cats["discharge"]
date = storm_stage_cats["date"]
stage = storm_stage_cats["stage"] - 79.331
date_stage = storm_stage_cats["date"]
rainfall = storm_rain_cats["rainfall"]
date_rainfall = storm_rain_cats["date"]

#set locator and formatter

hours    = matplotlib.dates.HourLocator()   # every year
months   = matplotlib.dates.MonthLocator()  # every month
hoursFmt = matplotlib.dates.DateFormatter("%H")

#create plot

fig=matplotlib.pyplot.figure()
ax=fig.add_subplot(311)
ax.bar(date_rainfall,rainfall,color="blue",label="Precipitation")
ax.xaxis.set_major_locator(hours)
ax.xaxis.set_major_formatter(hoursFmt)
matplotlib.pyplot.ylabel("Precipitation[mm]")
matplotlib.pyplot.grid(True)
matplotlib.pyplot.legend()

ax=fig.add_subplot(312)
ax.plot(date,discharge,color="red",label="discharge")
ax.xaxis.set_major_locator(hours)
ax.xaxis.set_major_formatter(hoursFmt)
matplotlib.pyplot.ylabel("discharge[m3/s]")
matplotlib.pyplot.grid(True)
matplotlib.pyplot.legend()

ax=fig.add_subplot(313)
ax.plot(date_stage,stage,color="green",label="stageheight")
ax.xaxis.set_major_locator(hours)
ax.xaxis.set_major_formatter(hoursFmt)
matplotlib.pyplot.ylabel("stageheight[m]")
matplotlib.pyplot.grid(True)
matplotlib.pyplot.legend()
matplotlib.pyplot.xlabel("Hours")

fig=matplotlib.pyplot.figure(1)
fig.autofmt_xdate() #rotates dates in xaxis

Odpowiedzi:

0 dla odpowiedzi № 1

Myślę, że potrzebujesz wspólnego xAxis Tam powinieneś dodać podploty w inny sposób. Zwykle robię to podobnie do subplots_demo.py, które można znaleźć tutaj: http://matplotlib.org/examples/pylab_examples/subplots_demo.html